简体   繁体   English

如何获得的返回值 <select>使用NiceForm插件

[英]How to get the return value of <select> that uses NiceForm Plugin

I used a plugin called niceform NiceForms and it changes my form elements to <a> and <li> tags. 我使用了一个名为niceform NiceForms的插件,它将其表单元素更改为<a><li>标记。 I'm having hard time getting the return value of the selected item. 我很难获取所选项目的返回值。

please see my jsbin here: http://jsbin.com/ufoxuc 请在这里查看我的jsbinhttp//jsbin.com/ufoxuc

$(function(){

    $("#gender").change(function () {
       alert($(this).val());
    });

});

Please help. 请帮忙。 thanks! 谢谢!

Solution is simple, juste select the child of your select and access to the value 解决方案很简单,只需选择您选择的子项并获取值

$("#gender").change(function () {
   var value = $("#gender option:selected").val();
   alert(value);
});

Hope that it helps 希望对您有所帮助

实际上没有选择,它们只是<div><select> <div>样式,因此change()函数从不触发,您确定插件没有提供钩子来监听change()事件吗?

You could do it like: 您可以这样做:

Edit the original niceforms.js and replace following line (probably line number 544): 编辑原始的niceforms.js并替换以下行(可能是行号544):


el.lnk._onclick = el.onclick || function () {};

//WITH following

el.lnk._onclick = el.onclick || function () {
    if (this.ref.oldClassName.indexOf("NFOnChange") > -1){
        this.ref.options[this.pos].selected = "selected";
        //Call the original onchange event
        this.ref.onchange();
    }
};

After doing this, you need to add the NFOnChange class to your select tag, like this: 完成此操作后,需要将NFOnChange类添加到select标记中,如下所示:


<select size="1" name="gender" id="gender" class="NFOnChange" onchange="yourFunction()">

Thats how i managed to make it work. 那就是我设法使其工作的方式。 Hope it helps 希望能帮助到你

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM