JavaScript-来自文本字段的值未返回任何内容
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了JavaScript-来自文本字段的值未返回任何内容,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2031字,纯文字阅读大概需要3分钟。
内容图文
![JavaScript-来自文本字段的值未返回任何内容](/upload/InfoBanner/zyjiaocheng/677/f4a54026c7304125b817df4e3a65e36c.jpg)
我正在尝试构建一个小应用程序,在该应用程序中,用户输入商店名称,该名称将成为图像的替代文本,其商店的URL将变为ah ref,然后将生成一些复制和粘贴代码,以供其使用网站.
我的问题是,当尝试使用原始JavaScript读取商店名称的值时,没有任何显示.
请看我的小提琴:
http://jsfiddle.net/willwebdesigner/gVCcm/
$(document).ready(function() {
// Creates a method and prototype for the Array for splicing up words
Array.prototype.removeByValue = function(val) {
for(var i=0; i<this.length; i++) {
if(this[i] == val) {
this.splice(i, 1);
break;
}
}
}
var myStore = {
storeName: document.getElementById("storeName").value,
Url: document.getElementById("yourURL"),
instructions: "<p>Please copy the code above and paste it into your webpage to display the shop4support logo and a link to your store.</p>",
blackLogo: function() {
return "<img src="https://www.shop4support.com/Resources/home/information/InformationForProviders/Availables4s-bk.jpg" alt="" + this.storeName + " is available on shop4support" />";
}
}
$("#urlForm").submit(function(e) {
// Clear output form first
$(output).html(' ');
e.preventDefault();
// Create an array for conditional statements
var address = [];
address = $(myStore.Url).val().split("www");
// Need to put a conditional in here to detect if https://
if(address[0] === "https://") {
$(output)
.slideDown()
.prepend("<a href=""+ $(myStore.Url).val() + "">" + myStore.blackLogo() + "</a> ")
.append(myStore.instructions);
} else if(address[0] === "http://") {
// Remove the http part off the URL
var removeHttp = address;
removeHttp.removeByValue('http://');
$(output)
.slideDown()
.prepend("<a href="https://www" + removeHttp + "">" + myStore.blackLogo() + "</a> ")
.append(myStore.instructions);
} else {
$(output)
.slideDown()
.prepend("<a href="https://"+ $(myStore.Url).val() + "">" + myStore.blackLogo() + "</a> ")
.append(myStore.instructions);
}
});
});
谢谢威尔
解决方法:
将您的代码更新为:
$("#urlForm").submit(function(e) {
myStore.storeName= (document.getElementById("storeName").value);
/* The rest of your code */
}
内容总结
以上是互联网集市为您收集整理的JavaScript-来自文本字段的值未返回任何内容全部内容,希望文章能够帮你解决JavaScript-来自文本字段的值未返回任何内容所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。