jQuery 将文本输入值传递给插件选项
我在任何地方都找不到我正在寻找的答案。我有一个生成条形码的插件。你所要做的就是告诉它渲染条形码的元素,它就会把它吐出来。例如:
$("#barcode-target").barcode("Output Goes Here", "code39",{barWidth:2, barHeight:30});
will put a barcode that says "Output Goes Here" into the div #barcode-target. However, I need it to generate a barcode with the value of a certain text input. I tried doing something along the lines of$(function(){
$("#barcode").keyup(function () {
var value = $(this).val();
$("#barcode-target").text(value);
}).keyup();
});
当然,这只会在 div 中放入普通字符。我被困住了!
编辑 我也试过了
$(function(){
var barcodeVal = $("#barcode").val();
$("#barcode-target").barcode("barcodeVal", "code39",{barWidth:2, barHeight:30});
});
还是不行...
I can't find quite the answer I'm looking for anywhere. I have a plugin that generates barcodes. All you do is tell it what element to render the barcode, and it spits it out. For example:
$("#barcode-target").barcode("Output Goes Here", "code39",{barWidth:2, barHeight:30});
will put a barcode that says "Output Goes Here" into the div #barcode-target.
However, I need it to generate a barcode with the value of a certain text input. I tried doing something along the lines of
$(function(){
$("#barcode").keyup(function () {
var value = $(this).val();
$("#barcode-target").text(value);
}).keyup();
});
Which, of course, only puts plain characters in the div. I'm stuck!
Edit
I've also tried
$(function(){
var barcodeVal = $("#barcode").val();
$("#barcode-target").barcode("barcodeVal", "code39",{barWidth:2, barHeight:30});
});
Still nothing...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要按照您所说的方式创建条形码:
You need to create a barcode the way you said:
关于您的编辑,如果您想要传递
barcodeVal
变量的值,则不应将名称放在引号中。否则,您将发送一个字符串文字。
或者您可以放弃该变量,并将
.val()
调用直接放在对barcode()
的调用中。With regard to your edit, if you're wanting to pass the value of the
barcodeVal
variable, you shouldn't put the name in quotes.Otherwise you were sending a String literal.
Or you could forego the variable, and place the
.val()
call directly in the call tobarcode()
.