admin管理员组文章数量:1026989
I have a datalist which looks like this
<datalist id="properties">
<option value="property name"></option>
<option value="property"></option>
</datalist>
Now I'm using this code to find where values entered by the user is in the list:
var user_property = $('#user_property').val().toLowerCase(); // taken from input type with id user_property
var pro = $('#properties').find("option[value="+user_property.replace(' ','-')+"]");
if(pro != null && pro.length > 0)
{
// run some code
}
else
{
// show error popup
}
I am getting error in var pro = $('#properties').find("option[value="+user_property.replace(' ','-')+"]");
Error code says Syntax error, unrecognized expression: option[value=property name]
How to get rid of this error?
I have a datalist which looks like this
<datalist id="properties">
<option value="property name"></option>
<option value="property"></option>
</datalist>
Now I'm using this code to find where values entered by the user is in the list:
var user_property = $('#user_property').val().toLowerCase(); // taken from input type with id user_property
var pro = $('#properties').find("option[value="+user_property.replace(' ','-')+"]");
if(pro != null && pro.length > 0)
{
// run some code
}
else
{
// show error popup
}
I am getting error in var pro = $('#properties').find("option[value="+user_property.replace(' ','-')+"]");
Error code says Syntax error, unrecognized expression: option[value=property name]
How to get rid of this error?
Share Improve this question edited Jan 28, 2015 at 17:53 k0pernikus 66.4k77 gold badges240 silver badges359 bronze badges asked Jan 28, 2015 at 17:28 runningmarkrunningmark 7604 gold badges13 silver badges33 bronze badges3 Answers
Reset to default 20try adding quotes, as:
var pro = $('#properties').find("option[value='"+user_property.replace(' ','-')+"']");
or better break it down to:
var replaced = user_property.replace(' ','-');
var pro = $('#properties').find("option[value='"+replaced+"']");
if you want to check for text like "property name" then you could directly do:
var pro = $('#properties').find("option[value='"+user_property+"']");
Try adding quotes around the value and it will work.
$('#properties').find("option[value='property name']")
You need to add single quote for your value like
var pro = $('#properties').find("option[value='"+user_property.replace(' ','-')+"']");
I have a datalist which looks like this
<datalist id="properties">
<option value="property name"></option>
<option value="property"></option>
</datalist>
Now I'm using this code to find where values entered by the user is in the list:
var user_property = $('#user_property').val().toLowerCase(); // taken from input type with id user_property
var pro = $('#properties').find("option[value="+user_property.replace(' ','-')+"]");
if(pro != null && pro.length > 0)
{
// run some code
}
else
{
// show error popup
}
I am getting error in var pro = $('#properties').find("option[value="+user_property.replace(' ','-')+"]");
Error code says Syntax error, unrecognized expression: option[value=property name]
How to get rid of this error?
I have a datalist which looks like this
<datalist id="properties">
<option value="property name"></option>
<option value="property"></option>
</datalist>
Now I'm using this code to find where values entered by the user is in the list:
var user_property = $('#user_property').val().toLowerCase(); // taken from input type with id user_property
var pro = $('#properties').find("option[value="+user_property.replace(' ','-')+"]");
if(pro != null && pro.length > 0)
{
// run some code
}
else
{
// show error popup
}
I am getting error in var pro = $('#properties').find("option[value="+user_property.replace(' ','-')+"]");
Error code says Syntax error, unrecognized expression: option[value=property name]
How to get rid of this error?
Share Improve this question edited Jan 28, 2015 at 17:53 k0pernikus 66.4k77 gold badges240 silver badges359 bronze badges asked Jan 28, 2015 at 17:28 runningmarkrunningmark 7604 gold badges13 silver badges33 bronze badges3 Answers
Reset to default 20try adding quotes, as:
var pro = $('#properties').find("option[value='"+user_property.replace(' ','-')+"']");
or better break it down to:
var replaced = user_property.replace(' ','-');
var pro = $('#properties').find("option[value='"+replaced+"']");
if you want to check for text like "property name" then you could directly do:
var pro = $('#properties').find("option[value='"+user_property+"']");
Try adding quotes around the value and it will work.
$('#properties').find("option[value='property name']")
You need to add single quote for your value like
var pro = $('#properties').find("option[value='"+user_property.replace(' ','-')+"']");
本文标签: javascriptSyntax errorunrecognized expression optionvalueproperty nameStack Overflow
版权声明:本文标题:javascript - Syntax error, unrecognized expression: option[value=property name] - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1738457075a1574041.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论