【问题标题】:Jquery attr doesnt work on YiiJquery attr 在 Yii 上不起作用
【发布时间】:2014-11-24 06:56:45
【问题描述】:

我正在尝试使用 Jquery 更改元素值,但它不起作用...

这是我的小部件,其中有我的元素“标签”,我想在编辑时将其更改为 textField...

$this->widget('EditableGrid', array(
    'dataProvider' => $dataProvider->searchbyID($invoice_id),
    'template' => '{items}{buttonCreateRow}{pager} ',
    'id' => 'InvoiceLine-grid',
    'rowTemplate' => $row_template,
    'columns' => array(   
            array(
            'class' => 'EditableGridColumn',
            'header' => '',
            'name' => 'InvoiceLine_{gridNum}_{rowNum}_edit',
            'imageurl'=> Yii::app()->request->baseUrl.'/images/update.png',
            'tag' => 'button',
            'tagHtmlOptions' => array(
            'onclick'=>'editline(this)',
                )
            ),
            array(
            'class' => 'EditableGridColumn',
            'header' => 'StentysRef',
            'name' => '[{gridNum}][{rowNum}]stentysproductref',
            'tag' => 'laabel',          
            'tagHtmlOptions' => array(
                'style'=>'background-color:#FFF;border-color:#FFF',
            'onkeyup'=>'stentysref(this)',
                'readonly'=>true
                )
            ), 

我的 Jquery 是,

(您可以看到 removeAttr 有效,但 attr 无效)

       function editline(obj){
            $("#InvoiceLine_1_"+row+"_stentysproductref").attr("tag","textField");
            $("#InvoiceLine_1_"+row+"_stentysproductref").removeAttr("readonly");
}

【问题讨论】:

    标签: php jquery yii


    【解决方案1】:

    使用 jQuery 1.6 中添加的 .prop()removeProp(),因为 .attr() 方法有时在检索某些属性时会考虑属性值,这可能会导致行为不一致。

    function editline(obj){
        $("#InvoiceLine_1_"+row+"_stentysproductref").prop("tag","textField");
        $("#InvoiceLine_1_"+row+"_stentysproductref").removeProp("readonly");
    }
    

    API Doc for .prop()

    【讨论】:

    • 您是否在浏览器上收到任何控制台错误?请与您的问题陈述分享一个 jsfiddle 链接,以便我可以更好地帮助您。
    • 我没有收到任何错误。当我点击编辑时,我只想要一个文本字段......任何溶胶?
    • 还有row 是干什么用的?而你在function editline(obj){ 中传递了obj 但没有使用它,那为什么要传递它呢?
    • 函数编辑线(obj){ var status = ; if(status == "1") { var id = obj.id; var trun = id.substring(14); var row= trun.substr(0, trun.indexOf('')); $("#InvoiceLine_1"+row+"_stentysproductref").attr("tag","textField");}
    • 请分享您的html代码并分享jsfiddle,这有助于我更好地帮助您。
    【解决方案2】:

    如果您使用 EditableGrid 小部件而不指向 AR 模型,则行 id 看起来像

    $('#_1_'+row+'stentysproductref').
    

    我会在以后的更新中考虑到它。谢谢。

    【讨论】:

      猜你喜欢
      • 2016-11-02
      • 1970-01-01
      • 2012-08-16
      • 1970-01-01
      • 2012-09-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多