在我的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,我打電話時,我點擊單選按鈕巴塞羅那 –