I have problem with getting values from select option when use JQuery UI $('#id').combobox(). When i use simple JQuery without Ui it work but when i use Ui it can't get Value. Here some of my HTML code:
我在使用JQuery UI $('#id')。combobox()时从select选项获取值时遇到问题。当我使用简单的JQuery而不使用Ui时,它可以工作,但是当我使用Ui时,它无法获得价值。这里有一些我的HTML代码:
<table>
<tr>
<td>Reset by: </td>
<td>
<select name="resetType" id="resetType">
<option value="email" selected>Email</option>
<option value="phone">Phone's Number</option>
<option value="username">Username</option>
</select>
</td>
</tr>
<tr>
<td id="type"></td>
<td><input type="text" name="type"/></td>
</tr>
</table>
Here my JQuery Code:
这是我的JQuery代码:
$(function(){
$('#resetType').combobox(); // Code have Problem
switch($('#resetType').val()){
case 'email':
$('#type').html('Email: ');
break;
case 'phone':
$('#type').html('Phone: ');
break;
case 'username':
$('#type').html('Username: ');
break;
}
})
1 个解决方案
#1
1
I did [name*="type"]
here because you didn't give that textbox an ID or anything, so i'm simply searching for it by name
attribute.
我在这里做了[name * =“type”]因为你没有给那个文本框一个ID或任何东西,所以我只是按名称属性搜索它。
$('#resetType').on('change', function () {
$('[name*="type"]').val($(this).find('option:selected').val());
});
Here's a working demo: http://jsfiddle.net/JwB6z/2/
这是一个有效的演示:http://jsfiddle.net/JwB6z/2/
#1
1
I did [name*="type"]
here because you didn't give that textbox an ID or anything, so i'm simply searching for it by name
attribute.
我在这里做了[name * =“type”]因为你没有给那个文本框一个ID或任何东西,所以我只是按名称属性搜索它。
$('#resetType').on('change', function () {
$('[name*="type"]').val($(this).find('option:selected').val());
});
Here's a working demo: http://jsfiddle.net/JwB6z/2/
这是一个有效的演示:http://jsfiddle.net/JwB6z/2/