当前位置:首页 > 编程笔记 > 正文
已解决

JS,jQuery常用语法记录

来自网友在路上 11018101提问 提问时间:2023-11-21 15:10:56阅读次数: 101

最佳答案 问答题库1018位专家为你答疑解惑

JS,jQuery常用语法记录

JS常用语法:
1.操作剪切板 [可能无法在某些浏览器中正常工作]
document.execCommand("copy")/document.execCommand("cut")// 复制链接function doCopyLink(id){$("#hiddenUrl").val("/article/viewArticle?id=" + id);var url = document.getElementById("hiddenUrl");url.select();document.execCommand("Copy");alert("复制链接成功!");}JQuery常用语法:
1.id选择器
$("#myElement").text(); [元素不存在返回undefined]
$("#myElement").text("Hello, world!");
追加元素使用append()或prepend()方法2.事件处理程序:
使用on()方法来附加事件处理程序。
$("#myButton").on("click", function() { alert("Button clicked!"); });
将在单击id为myButton的按钮时显示警报框。3.获取和设置属性:
使用.attr()方法来获取或设置元素的属性。
$("#myImage").attr("src", "newimage.jpg");
将把id为myImage的图像的src属性设置为"newimage.jpg"4.获取和设置内容:
使用.text().html()方法来获取或设置元素的文本内容或HTML内容。
$("#myElement").text("Hello, world!");
将把id为myElement的元素的文本内容设置为"Hello, world!"5.添加或删除类:
使用.addClass().removeClass()方法来添加或删除元素的类。
$("#myElement").addClass("highlight");
将向id为myElement的元素添加名为"highlight"的类。6.遍历元素:
使用.each()方法遍历匹配选择器的每个元素。
$("li").each(function() { console.log($(this).text()); });
将输出页面中每个li元素的文本内容。7.发送AJAX请求:
使用.ajax()方法发送AJAX请求。
$.ajax({ url: "example.php", success: function(data) { console.log(data); } });8.获取select标签内选中的标签
var selectedValue = $('select').find(':selected').val()/.text();9.iframe打开新的页面
/**
* 查看所有业务随访计划*/
function getfollowNoticePlan(){window.frames["followModalFrame"].innerHTML = "";$('#followModalFrame').attr('src', BASE_PATH + "/FollowNoticePlan/followNoticePlanStatistics?trialId="+id);$('#followModal').modal('show');
}
//  modal弹窗
<div class="modal fade" id="followModal" tabindex="-1" role="dialog" aria-labelledby="countModalLabel" aria-hidden="true"><div class="modal-dialog"  style="width: 95%;"><div class="modal-content" ><div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button><h4 class="modal-title" id="followModalLabel">预约随访</h4></div><div class="modal-body" ><iframe src="" width="100%" id="followModalFrame" name="countFrame" style="border: 0px;min-height: 825px;"></iframe></div></div></div></div>清除JS缓存 浏览器强制刷新: Ctrl+F5
查看全文

99%的人还看了

猜你感兴趣

版权申明

本文"JS,jQuery常用语法记录":http://eshow365.cn/6-41332-0.html 内容来自互联网,请自行判断内容的正确性。如有侵权请联系我们,立即删除!