Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 临时标记<;b>;滑动分页_Jquery - Fatal编程技术网

Jquery 临时标记<;b>;滑动分页

Jquery 临时标记<;b>;滑动分页,jquery,Jquery,我是Jquery的新手。我需要el方法text()在div2中改进粗体标记,而不仅仅是文本 <!DOCTYPE html> <html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("#btn1

我是Jquery的新手。我需要el方法text()在div2中改进粗体标记,而不仅仅是文本

<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("#btn1").click(function(){
    $("#div1").text("Text: " + $("#test").text());
  });
  $("#btn2").click(function(){
    $("#div2").text("HTML: " + $("#test").html());
  });
});
</script>
</head>

<body>
<p id="test">This is some <b>bold</b> text in a paragraph.</p>
<button id="btn1">Show Text</button>
<button id="btn2">Show HTML</button>
<div id="div1"></div>
<div id="div2"></div>
</body>
</html>

$(文档).ready(函数(){
$(“#btn1”)。单击(函数(){
$(“#div1”).text(“text:+$(“#test”).text());
});
$(“#btn2”)。单击(函数(){
$(“#div2”).text(“HTML:+$(“#test”).HTML());
});
});

这是段落中的粗体文本

显示文本 显示HTML
结果如下。我不想要加粗的,但要加粗的文本

HTML: This is some <b>bold</b> text in a paragraph.
HTML:这是段落中的粗体文本。
使用

$('#div1').html(“这是段落中的粗体文本”);
试试这个

$("#btn1").click(function(){
    $("#div1").text("Text: " + $("#test").html());
  });
  $("#btn2").click(function(){
    $("#div2").html("HTML: " + $("#test").html());
  });
这是演示

jQuery.text():获取匹配元素集中每个元素的组合文本内容,包括其子元素,或设置匹配元素的文本内容

jQuery.html():获取匹配元素集中第一个元素的html内容或设置每个匹配元素的html内容

使用下面的代码

$(document).ready(function(){
  $("#btn1").click(function(){
    $("#div1").html("Text: " + $("#test").text());
  });
  $("#btn2").click(function(){
    $("#div2").html("HTML: " + $("#test").html());
  });
});

您需要调用
html
而不是
text
非常感谢。请原谅我的问题。我真的是个新手
$(document).ready(function(){
  $("#btn1").click(function(){
    $("#div1").html("Text: " + $("#test").text());
  });
  $("#btn2").click(function(){
    $("#div2").html("HTML: " + $("#test").html());
  });
});