在我的page1.php我想切换page2.php的可见性。使用Ajax和单选按钮切换可见性
我使用下面的代码:
<input type="radio" name="city" value="Barcelona" onclick="getPage2(this.value);"> Barcelona
<input type="radio" name="city" value="Manchester"> Manchester
我使用此代码调用使page2.php:
function getPage2()
{
$.ajax({
type: "GET",
url: "page2.php",
success: function(result){
$("#show_results").html(result);
}
});
};
我想要显示的则page2.php只有在单选按钮如果没有选择任何单选按钮或“麦克切斯特”单选按钮,则不会显示任何内容(隐藏它)。
UPDATE
我解决它。这其实很简单。
<input type="radio" name="city" value="Barcelona" onclick="getPage2(this.value);"> Barcelona
<input type="radio" name="city" value="Manchester" onclick="getPage2(this.value);"> Manchester
我展示,我使用此代码隐藏使page2.php:
function getPage2()
{
var var_name = $("input[name='city']:checked").val();
$.ajax({
type: "GET",
url: "page2.php",
success: function(result){
if(var_name == "Barcelona")
$("#show_results").html(result).show();
else
$("#show_results").html(result).hide();
}
});
};
感谢你们反正。
嗨马克斯,我不想隐藏点击输入。我想隐藏page3.php,我打电话时,我点击单选按钮巴塞罗那 –