jquery前端相关记录

1.获取相同name属性的input的值并做遍历 

$("[name='nums']").each(function(){
    alert($(this).val()); // 得到的是div对象
   
});
jQuery中each类似于javascript的for循环 
但不同于for循环的是在each里面不能使用break结束循环,也不能使用continue来结束本次循环,想要实现类似的功能就只能用return,
break           用return false
continue      用return ture

2.微信支付需要把一个url作为参数传给另一个url    ,那参数url 需要encodeURIComponent()去转换一下

window.location.href="/outpage/createEwm?qrtext="+encodeURIComponent(wxUrl);

3.使用summernote富文本编辑器,存入数据库的内容为<h1>aaaa</h1>,取出来放入div还是<h1>aaaa</h1>

解决方法:

 2.2通过js将这段字符插入到html中,让html自己解析html标签

  html代码:

<textarea type="text"  name="content" id="summernote"></textarea>

<input type="hidden" id="article_content" value="{$post.content}">

  先将这些内容放在一个input中,给这个input一个hidden属性,然后通过js吧这段代码插入到textarea中,让html通过浏览器自己解析:

  js代码:

$(function(){
         var innerhtml = $("#article_content").val();
         $("#summernote").val(innerhtml);
});

或者使用vue时:

<div class="detail-bd" id="content">
    <#--{{bean.arContent|delHTMLTag}}-->

</div>

----------------上面是页面------------------------

----------------下面是js------------------------

that.$http.post("/。。。。/。。。。.json", {
    id: that.id,pageIndex:that.pageIndex
}, {emulateJSON: true}).then(function (response) {
    that.bean=response.data.bean;//获取到详情对象
    $("#content").html(that.bean.arContent);//取出描述内容  使用这种方式给予赋值
}).catch(function (response) {
})

结果如下:

内容被html解析出来了,该换行换行,该加粗加粗了

猜你喜欢

转载自blog.csdn.net/ajax_yan/article/details/89512858