【问题标题】:Element value set by modal button action is not working in jquery?由模态按钮操作设置的元素值在 jquery 中不起作用?
【发布时间】:2017-07-25 14:17:09
【问题描述】:

我的 jquery 代码是:(这将在模态按钮单击时触发)

$(document).on('click', '.js-modal-remove-button', function () {
    $('#code-output').attr('da-url',"1111");
});

我的html代码是:

<input type="hidden" name="problemCode" id="code-output" da-url=2/>

问题是我的页面中有一个按钮,在这个按钮上单击模态打开并且在模态中还有一个包含类的按钮 js-modal-remove-button 关于我需要设置我的主页(模式打开按钮所在的位置)da-url 值的操作

【问题讨论】:

  • 点击 .js-modal-etc 的操作是否有效?做一个console.log 确保调用它。
  • 是的,它正在工作
  • 并且您不会多次重复 id#code-output 对吗?...也许如果您创建一个新的绑定类.. 比如 $(document).on('click', ' .sendDaUrl', 函数 () { ...

标签: javascript jquery html twitter-bootstrap


【解决方案1】:

只需为您的按钮添加另一个类并使用此 jquery
HTML

<button class="js-modal-remove-button model_button_class"></button>

jQuery

$(document).on('click', '.js-modal-remove-button .model_button_class', function () {
    $('#code-output').attr('da-url',"1111");
});

这里.model_button_class 是另一个类。
我想它会对你有所帮助。

【讨论】:

    【解决方案2】:

    试试这个:

    $('.js-modal-remove-button .model_button_class').on('click',function(){
        $('#code-output').attr('da-url',"1111");  });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-09-02
      • 2022-11-03
      • 1970-01-01
      • 2014-12-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多