简体   繁体   English

显示具有多个值属性的选择框值

[英]Display the select box value having multiple value attribute

<select class="form-control"  id="country" name="country">
    <option data-othervalue=hellow world value="some value">three</option>
</select>

<script>
    $('#country').change(function () {
        var otherValue=$(this).find('option:selected').attr('data othervalue');

        $('#tempselect').val(otherValue);

    });
</script>

//Input which shows secondary value from select box
<input type="text" id="tempselect">

I know my script is wrong but how can I get the second value ie 'data-other value' to the above textbox我知道我的脚本是错误的,但我怎样才能获得第二个值,即“数据其他值”到上面的文本框

 <option data-othervalue=hellow world value="some value">three</option> 

 <option data-othervalue="hellow world" value="some value">three</option>

HTML isn't very strict with syntax and gives many possibilities to achieve one thing. HTML 的语法不是很严格,并且为实现一件事提供了许多可能性。 One ways are better than the others and they are called as good practices.一种方法比其他方法更好,它们被称为良好实践。

Regarding you rquestion: attributes values can be specified without double-quotes as long as the value is string without any spaces, when space is introduced, browser reads only first word for attribute value, that's why you need to rap hellow world in double-quotes.关于你的问题:属性值可以不用双引号指定,只要值是没有空格的字符串,当引入空格时,浏览器只读取属性值的第一个单词,这就是为什么你需要用双引号来hellow world .

Having said that, good practice is to always use double quotes around the attribute values, no matter if they consist of one or more words.话虽如此,好的做法是始终在属性值周围使用双引号,无论它们是由一个还是多个单词组成。

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

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