我需要做的是:
string匹配。案例1:在Json中设置行业数据时
["", "app.php", "automotive", "tradeshows"]JQuery代码:
$( document ).ready(function()
{
var match = window.location.pathname.split("/");
console.log(match[3]);
if(match[3]=="conferences")
{
console.log("true");
$('#radio3').prop('checked', true);
}
else if(match[3]=="tradeshows")
{
console.log("afeef");
$('#radio2').prop('checked', true);
}
else
{
$('#radio1').prop('checked', true);
}
});案例2:当Json中没有设置行业数据时
["", "app.php", "tradeshows"]string来匹配Json,所以有没有其他的方法来匹配Json和string发布于 2015-07-10 09:24:16
您可以使用jQuery indexOf()来检测automotive是否可用。见下面的代码
function myFunction(page) {
var pages = ["", "app.php", "automotive", "tradeshows"];
var a = pages.indexOf(page);
document.getElementById("demo").innerHTML = a;
}<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p>Click the button to display the position of the element "tradeshows":</p>
<button onclick="myFunction('automotive')">Check for automotive</button>
<button onclick="myFunction('automotive1')">Check for automotive1</button>
<p id="demo"></p>
注意: indexOf方法是在JavaScript 1.6中引入的,在Internet 8和更早版本中不起作用。
https://stackoverflow.com/questions/31336838
复制相似问题