如何将变量的内容写入here 的文本区域用JavaScript?
如何使用 javascript 将变量的内容写入 here
的文本区域?我想提示用户使用被调用的函数 onclick 并将他们输入的内容存储到变量中,然后将保存到该变量的字符串写入与表单/输入/提示相同的 。
我认为这可以通过类属性访问列来完成 理想情况下,我希望函数独立且健壮,以便我可以根据类属性将它们用于多个不同的列。
<html>
<head>
<link href="style.css" rel="stylesheet" type="text/css">
<title>asdfsadf</title>
</head>
<body bgcolor="#000088">
<script type="text/javascript">
function editDates()
{
var dates = prompt("Fill in date(s) of absence",
"Example: Travel 1/7 - 2/10");
document.write.
}
</script>
<table class="mainTable" cellspacing="0" border="1"
cellpadding="1" width="100%" height="100%">
<tr>
<td>name</td><td class="r1c1">
<form method="link" action="index.html" onClick="editDates();">
<input type="button" name="submit" value="Edit"/></form>
</td></tr></body></html>
How can I write the contents of a variable into the text area of a <td>here</td>
with javascript? I would like to prompt the user using the called function onclick and store what they type into a variable and then write the string saved to that variable into the same <TD>
that the form/input/prompt function call is in.
I'm thinking that this can be done by accessing the column via the class attribute.
Ideally, I'd like the function(s) to be independent and robust such that I can use them for several different columns based on the class attributes.
<html>
<head>
<link href="style.css" rel="stylesheet" type="text/css">
<title>asdfsadf</title>
</head>
<body bgcolor="#000088">
<script type="text/javascript">
function editDates()
{
var dates = prompt("Fill in date(s) of absence",
"Example: Travel 1/7 - 2/10");
document.write.
}
</script>
<table class="mainTable" cellspacing="0" border="1"
cellpadding="1" width="100%" height="100%">
<tr>
<td>name</td><td class="r1c1">
<form method="link" action="index.html" onClick="editDates();">
<input type="button" name="submit" value="Edit"/></form>
</td></tr></body></html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不过,我建议使用 jQuery,它对初学者更友好/更不容易出错。在这种情况下,它将是:
I'd recommend using jQuery though, much more beginner friendly / less error prone. In that case it would be:
安装 mootools,然后查看我为您创建的 jsfiddle.net 示例。添加“edit_button”类名的任何按钮元素(或任何与此相关的元素)都会将其父表格单元格的内容更改为来自用户提示输入的响应。
Install mootools, then check out this jsfiddle.net example I have created for you. Any button element (or any element for that matter) you add the class name of "edit_button" to will then change the contents of it's parent table cell to the response from the users prompt input.