对于form来讲,js有个特殊的object值叫FormData, 提交的都是序列化的内容。 如果要用FormData获取当前表格的对象, const form = document.getElementById('myForm'); const formData = new FormData(form); 获取某个input的值: const currentValue = formData.get('inputName'); 连接当前值和新值...
Read More »TimeLine Layout
3 月, 2023
2 月, 2023
-
18 2 月
JS表格前端验证
JS对表格验证分为前端验证和后端验证,前端验证比较容易理解。后端验证就是通过input发送过来的ajax,php通过判断post的值来做出反应。 1:检查input 字段是否为空 你可以用Input的value元素来检查: const myInput = document.getElementById("myInput"); if (myInput.value === "") { // input is empty...
Read More » -
3 2 月
7个超强的javascript方法(Method)所有前端必学
Some方法 循环数组所有item 当一个item 通过函数提供的条件,就会返回true , 这个函数必须要传回true 或者 false 当name 通过 name.includes("h") 这个条件, 这个函数就返回true 用法: 用作条件判断时候特别有用, 这个返回单个的item信息 const containsLetterH = names.some(name => { return name....
Read More »
1 月, 2023
-
20 1 月
如何给网站添加头部可关闭的横幅广告(像justnews一样)
首先在body标签上面添加横幅的html代码,通过设置top banner的display:none 来实现 一开始网站加载时候隐藏横幅: <div id="top-banner" style="display:none ;"> <a href="#"><img src="/path/to/banner.png" alt="" style="width:100%;"></a> <button id="close-button"></button> </...
Read More » -
19 1 月
WordPress怎样检测访客是否将网站添加到收藏以及如何统计收藏数量并且展示出来
下面这段代码通过Js来检测访客是否收藏本网站: if (window.external && ('AddFavorite' in window.external)) { // 当访客将本网站添加到浏览器收藏之后下面的代码会执行 } 将收藏数量统计到数据库,我们可以使用option的api。 利用update_option来更新收藏统计的字段: $bookmark_count = get_...
Read More » -
19 1 月
WordPress文章如何添加浏览次数
在主题文件夹下面的inc文件夹(如果没有就新建一个),新建一个postviews.php文件,然后在functions.php里面引入: require get_template_directory() . '/inc/postviews.php' 然后在文件里粘贴: <?php // function to display number of posts. // 可以在后台设置一个option来决定是否开启浏览次数 func...
Read More » -
15 1 月
jQuery的success\error和done\fail
在jQuery里面,success和error和done,fail函数做的事情都是一样的。 success参数特定回调函数当请求顺利完成时,然后从后端获取到data作为自己传递的参数。 $.ajax({ url: "some.php", type: "POST", data: { name: "John", location: "Boston" }, success: function(data) { console.log("Success:...
Read More » -
14 1 月
WordPress利用wp ajax 获取分类帖子并实现加载更多教程
首先html的button里面要加载data-category=category_id 的参数: <button class="category-button" data-category="1">Category 1</button> <button class="category-button" data-category="2">Category 2</button> <button class="category-button" data-category="3">Category 3</button> ...
Read More »