javascript - 点击功能不起作用;语法有问题吗?
问题描述
titleNotes
单击以“contentNotes”开头的 ID 和另一个以“contentNotes”开头的 ID 后,我试图在屏幕上显示警报。我第一次尝试使用这样的选择器是.css("cursor", "pointer")
成功的,所以我尝试在点击事件中实现这样的选择器,但这不起作用。我的语法有问题吗?
这是我的脚本:
$(document).ready(function() {
$("#changeIcon").click(function() {
$(this).find("i").toggleClass("fa-th fa-list");
$("body").find("#gridContainerMain").toggleClass("grid-container-3 grid-container-1");
$("body").find("#fillerColumnTop").toggleClass("grid-item-whole-column-filler-3-grid-container-state grid-item-whole-column-filler-1-grid-container-state");
});
$("[id^='titleNotes'],[id^='contentNotes']").css("cursor", "pointer");
$("[id^='titleNotes'],[id^='contentNotes']").click(function() {
alert("try"); //this is not alerting the user
});
$("[id^='deleteNotes']").click(function() {
var id = $(this).closest('div').attr('id');
console.log(id);
$.ajax({
url: "ajax/deleteidentifier.php",
type: "post",
data: {
id: id
}
})
.done(function(response){
if (JSON.parse(response)) {
alert("Moved to deleted folder.");
window.location.reload();
}
else {
alert("Failed!");
}
});
});
});
```
and here's the php code that contains the IDs in which the script would try to find
```
<?php
include "db.php";
$sql_display_notes = "SELECT * FROM notes WHERE user_id = '$account_id' AND archived_status = 'n' AND deleted_status = 'n'";
$query_sql_display_notes = $conn->query($sql_display_notes);
while ($result_query_sql_display_notes = $query_sql_display_notes->fetch_array()) {
$note_record = $result_query_sql_display_notes["note_record"];
$note_type = $result_query_sql_display_notes["note_type"];
$note_title = $result_query_sql_display_notes["note_title"];
$date_created = $result_query_sql_display_notes["date_created"];
$note_id = $result_query_sql_display_notes["note_id"]
?>
<div class="grid-padding-all" id="<?php echo $note_id; ?>">
<button type="button" id="deleteNotes<?php echo $note_id; ?>" class="close" data-dismiss="modal">×</button>
<input name="note_title" id="titleNotes<?php echo $note_id; ?>" class="note_display" disabled="" value="<?php echo $note_title ?>" title="created on <?php echo $date_created; ?>. Note type: <?php echo $note_type; ?>">
</input>
<textarea name="note_record" id="contentNotes<?php echo $note_id; ?>" class="note_display" disabled=""title="created on <?php echo $date_created; ?>. Note type: <?php echo $note_type; ?>"><?php echo $note_record; ?></textarea>
</div>
<?php
}
?>
解决方案
推荐阅读
- javascript - 键入时根据输入字段动态更改选择选项
- excel - 用“。”替换表达式在 VBA 中不起作用。
- java - 如果在 Wildfly 13 EE8 上部署多个应用程序,则 Infinispan 命令调度程序问题
- hyperledger-fabric - 如何根据参与者更改命名空间?
- c - 解析不同长度的串行消息
- javascript - 比较数组对象并显示差异
- java - Gradle 4.10.2 需要 Java 7 或更高版本才能运行。从命令行运行 gradle 时,您当前正在使用 Java 6
- reactjs - React 身份验证 API 调用中的“身份验证错误:网络错误”
- android - Android 中类似 Gmail 的注册布局
- mysql - MySQL LEFT JOIN 与 WHERE 函数调用产生错误结果