我有一个html选择元素,每当我点击其中一个选择选项时,它会获取选项值,然后进入此代码块,它将分割字符串并跟随if end语句重定向到另一个函数as期望。
注意:第一个代码块运行成功,第二个代码块没有运行,我不知道为什么if语句的嵌套导致什么都没有。当_has_feature_的值为true时,它仍然不会产生警报
$('#favorites').change(function () {
var strData = this.value.split("|")
var _url_ = strData[0];
var _redirect_id_ = strData[1];
var _redirect_ = strData[2];
var _has_feature_ = strData[3];
var id = strData[4];
if (_redirect_id_ == '1') {
RedirectI(_url_);
}
else if (_redirect_id_ == '2') {
Redirect(_url_);
}
else if (_redirect_id_ == '3') {
RedirectI(_url_ + _username);
}
else if (_redirect_id_ == '4') {
window.open(_url_);
}
});
下面不起作用!
$('#favorites').change(function () {
var strData = this.value.split("|")
var _url_ = strData[0];
var _redirect_id_ = strData[1];
var _redirect_ = strData[2];
var _has_feature_ = strData[3];
var id = strData[4];
var valuestring = id + "," + _redirect_id_ + "," + _redirect_;
if (_has_feature_ == "true") {
alert(has_feature);
// Features(valuestring);
}
else if (_has_feature_ == "false") {
if (_redirect_id_ == '1') {
RedirectI(_url_);
}
else if (_redirect_id_ == '2') {
Redirect(_url_);
}
else if (_redirect_id_ == '3') {
RedirectI(_url_ + _username);
}
else if (_redirect_id_ == '4') {
window.open(_url_);
}
}
});
答案 0 :(得分:0)
这是你的工作示例,只需将其放入更改功能......
$(function(){
var response = "google.com/|4|javascript: window.open|False|7";
var strData = response.split("|")
var _url_ = strData[0];
var _redirect_id_ = strData[1];
var _redirect_ = strData[2];
var _has_feature_ = strData[3];
var id = strData[4];
var valuestring = id + "," + _redirect_id_ + "," + _redirect_;
if (_has_feature_ == "True") {
alert(has_feature);
// Features(valuestring);
}
else if (_has_feature_ == "False") {
if (_redirect_id_ == '1') {
RedirectI(_url_);
}
else if (_redirect_id_ == '2') {
Redirect(_url_);
}
else if (_redirect_id_ == '3') {
RedirectI(_url_ + _username);
}
else if (_redirect_id_ == '4') {
window.open(_url_);
alert("Called");
}
}
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
&#13;