我試過將設置單選按鈕選中爲checked="checked"
但是,這似乎不起作用。 我試過使用無法在單選按鈕中設置選中的屬性(表格中的單選按鈕)
- $(id_radio).prop('checked',true);
- document.getElementById(「id_radio」)。checked = true;
- document.getElementById(「id_radio」)。checked = true;
- document.getElementById(「id_radio」)。checked;
- $(id_radio).attr('checked',checked);
但他們都不似乎正在改變的checked
的屬性checked="checked"
下面是我的代碼 js_file.js
$(document).ready(function(){
$("document").on("click",".class_radio3",function(){
var id_radio=$(this).attr('value');
$(id_radio).prop('checked',true);
console.log(id_radio);
});
});
我創建表
代碼<br>
<p class="uk-text-primary uk-text-bold"><u> General Message </u></p>
<table class="uk-table uk-border-rounded uk-grid-width-* uk-panel-box uk-text-justify" border="1">
<!--create top table -->
<tr> <!--tr defines a row --> <!-- define row 1 -->
<th class="uk-width-1-10"> Recipient </th> <!-- th defines a header cell-->
<th class="uk-width-1-3"> Message </th>
<th class="uk-width-1-10"> Action </th>
<th class="uk-width-1-10"> Default message </th>
</tr>
<!-- row 2 : display results onwards and creates dynamically -->
<!-- input fields at the bottom -->
<?php
include "../connect.php";
$get_data2admin = $db->query("SELECT ID,message,user FROM test_table_1 WHERE user='General'");
if($get_data2admin->num_rows >0){ //if selected rows is more than zero
while($row_msg = $get_data2admin->fetch_assoc()){
$row_msg_id=$row_msg['ID']; //$row_msg['ID'] directly using it wont display in id tag attribute
echo "<tr>";
echo "<td>".$row_msg['user']."</td>";
echo "<td>".$row_msg['message']. "</td>";
?>
<td><a href="#" id="<?php echo $row_msg_id; ?>" class="delete_button uk-text-danger">Delete</a></td>
<?php
if($row_msg['user']=='General'){
echo "<td>"."<input class='class_radio3' type='radio' name='name_radio2' value='$row_msg_id' checked=''/>"."</td>";
}
else{
echo "<td>"."-"."</td>";
};
echo "</tr>";
}
}
?>
</table>
可能是什麼問題?任何見解/解決方案?作爲PhP的初學者,任何建議都會有所幫助。謝謝
注 其打印出選擇,所以我不認爲它的選擇問題
阿里納斯的權利ID:如果我嘗試使用e.preventDefault在
$("document").on("click",".class_radio3",function(e){
e.preventDefault();
另一個問題單選按鈕變成不可點擊。那爲什麼?
這是打印還是沒有? console.log(def_radio); –
@HEMANTSUMAN錯字,我只是糾正了它,但是它確實打印了正確的#id – peekaboo
請包括直接的HTML - 客戶端看到的內容(PHP僅在服務器端)。你可以通過頁面源查看。 – allicarn