我想在下面的文本之前插入一个<span>(在LINK之前):
<li><a href="">LINK</a></li>
Run Code Online (Sandbox Code Playgroud)
所以,上面变成了
<li><a href=""><span>LINK</a></li>
Run Code Online (Sandbox Code Playgroud)
这是我的JQuery代码:
$('#mainnav li a').prepend('<span>');
Run Code Online (Sandbox Code Playgroud)
当我在firebug中查看代码之后,我知道<span></span>,如何才能获得开始span标记而不是结束标记?
我正在使用 prepend() 并且结果似乎有问题。
$('#element').prepend('<div><a href="http://google.com"><a href="http://test.com">Test.com</a> - A site</a></div>');
Run Code Online (Sandbox Code Playgroud)
并且 html 结果(也用 Firebug 查看)有问题:
<div>
<a href="http://google.com"></a>
<a href="http://test.com">Test.com</a> - A site
</div>
Run Code Online (Sandbox Code Playgroud)
(链接只是示例链接)
这种前置方式对我有用:
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
$("#learn-more-button").click(function() {
$("#main-text").load('ajax/learn-more.html #learn-more', function() {
$(this).prepend('<p> DARN </p>'); // <=== This here WORKS
$(this).hide().fadeIn(500); //Fade in
$("#main-text").animate({ // Then Animate
width:"500px",
left:'+=400px',},
400
);
});
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
这种前置方式对我不起作用:
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
$("#learn-more-button").click(function() {
$("#main-text").prepend('<p> DARN </p>'); // <=== This here doesn't work
$("#main-text").load('ajax/learn-more.html #learn-more', function() {
$(this).hide().fadeIn(500); //Fade in
$("#main-text").animate({ // Then Animate
width:"500px",
left:'+=400px',},
400
);
});
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
为什么第二种方式不起作用?怎么做才能让它发挥作用?
我不是一个真正的jQuery人,所以请帮助:)
我成功地使用jquery奇/偶选择器在表上创建了"老虎条纹".然后我添加了添加或删除行的功能.但是,我无法在添加/删除行时正确地使用条带化.它适用于添加/追加,但不适用于添加/前置或删除.以下是代码摘要......
$(document).ready(function(){
// click on Add Row button
$("#addButton").click(function(){
// add a row to table
addTableRow('#myTable');
// then re-apply tiger striping
stripeRows();
});
});
// remove specified row
function removeRow(row) {
$(row).parent("tr").remove();
stripeRows();
}
function StripeRows()
{
$("#myTable").each(function(){
$(this).find("tr:even").addClass("evenrow");
$(this).find("tr:odd").addClass("oddrow");
});
}
Run Code Online (Sandbox Code Playgroud) 今天我遇到了一个我不太了解的有趣的事情.这个(见下文)非常简单的jQuery脚本无法正常工作,基本上我想将前置div的背景颜色更改为红色,如果蓝色== true(这是真的).
var panel = $("<div id='panel'></div>");
var panelBg = $("#panel");
var test = "true";
var red = "true";
var blue = "true";
if (test == "true") {
if (red == "true") {
$("#first").prepend(panel);
}
if (blue == "true") {
panelBg.css("background-color","red");
}
}
Run Code Online (Sandbox Code Playgroud)
但是当我改变这一行时:
panelBg.css("background-color","red");
Run Code Online (Sandbox Code Playgroud)
对此:
$("#panel").css("background-color","red");
Run Code Online (Sandbox Code Playgroud)
该脚本有效.
工作演示:http: //jsfiddle.net/wK2jw/
我在listbuffer类型上使用prepend方法并观察一些奇怪的行为.prepend操作返回一个可接受的新列表.但是它不应该修改ListBuffer吗?在预先添加之后,我仍然看到ListBuffer的长度没有改变.我在这里错过了什么吗?
scala> val buf = new ListBuffer[Int]
buf: scala.collection.mutable.ListBuffer[Int] = ListBuffer()
scala> buf += 1
res47: buf.type = ListBuffer(1)
scala> buf += 2
res48: buf.type = ListBuffer(1, 2)
scala> 3 +: buf
res49: scala.collection.mutable.ListBuffer[Int] = ListBuffer(3, 1, 2)
scala> buf.toList
res50: List[Int] = List(1, 2)
Run Code Online (Sandbox Code Playgroud) VB.NET有一个方法,就像java一样,附加到StringBuilder类型的对象 但是我可以在这个对象之前添加(我的意思是在stringbuilder值之前添加一些字符串,而不是之后).这是我的代码:
'Declare an array
Dim IntegerList() = {24, 12, 34, 42}
Dim ArrayBefore As New StringBuilder()
Dim ArrayAfterRedim As New StringBuilder()
ArrayBefore.Append("{")
For i As Integer = IntegerList.GetLowerBound(0) To IntegerList.GetUpperBound(0)
ArrayBefore.Append(IntegerList(i) & ", ")
Next
' Close the string
ArrayBefore.Append("}")
'Redimension the array (increasing the size by one to five elements)
'ReDim IntegerList(4)
'Redimension the array and preserve its contents
ReDim Preserve IntegerList(4)
' print the new redimesioned array
ArrayAfterRedim.Append("{")
For i As Integer = IntegerList.GetLowerBound(0) To …Run Code Online (Sandbox Code Playgroud) 请考虑以下示例代码:
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#btn1").click(function(){
var btn = document.createElement("BUTTON");
btn.prepend("<b>Prepended text</b>. ");
});
});
</script>
</head>
<body>
<p>This is a paragraph.</p>
<button id="btn1">Prepend text</button>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
上面的代码在控制台中抛出错误,如下所示:
btn.prepend 不是函数
为什么会出现这个错误?请提出一个解决方案。谢谢
我想在字符串的单元格数组中添加一个字符串.例如,如果我:
q = {'1', '2'};
p = '3';
Run Code Online (Sandbox Code Playgroud)
我想做那样的事
a = prepend(q, p);
a =
'3' '1' '2'
Run Code Online (Sandbox Code Playgroud)
我怎样才能添加一个字符串?
我正在使用vue-masonry 插件,它可以让我轻松创建砌体网格。
我创建了一个无限加载的系统,您可以滚动到页面底部,并将新图片附加到与 vue-masonry 插件绑定的数组中。
当我创建一个轮询其他用户上传的新图片的系统时,出现了问题。这些新图片需要位于砌体网格的顶部。
该插件使用两个 Vue 指令masonry(父)和masonryTile(元素)。masonryTile有一个 v-for 循环遍历与我的 Vue 实例绑定的数组(它完成所有繁重的工作,预加载,清理等......)。
指令中有没有办法知道附加或前置的内容之间的差异?并尝试做出不同的反应(我知道砌体有一些追加/前置方法),但是在这里和使用这个插件,已经添加的项目(在开始时,所以前置可以与Vue一起使用),但没有砌体交互,也没有重绘(我尝试过)使用原型来触发重绘this.$redrawVueMasonry();)。
所以我不知道下一步该做什么。继续寻找一种方法来区分前置和附加并尝试将其绑定到各自的砌体方法?或者还有一个我没想到的方法...
预先感谢您的帮助
Ps:我认为我的代码并不真正相关,因为它更多的是优化插件的一种方法。如果您想要我的代码的某些特定部分,请在评论中告诉我!
prepend ×10
jquery ×6
html ×2
javascript ×2
string ×2
append ×1
cell-array ×1
css ×1
function ×1
listbuffer ×1
matlab ×1
scala ×1
vb.net ×1
vue.js ×1
vuejs2 ×1