如何将变量的内容写入here的文本区域用JavaScript?

发布于 2024-10-16 10:02:11 字数 1040 浏览 1 评论 0原文

如何使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

东走西顾 2024-10-23 10:02:11
document.getElementsByClassName('yourClass')[0].innerHTML = 'the content';

不过,我建议使用 jQuery,它对初学者更友好/更不容易出错。在这种情况下,它将是:

$('td.yourClass').html('the content');
document.getElementsByClassName('yourClass')[0].innerHTML = 'the content';

I'd recommend using jQuery though, much more beginner friendly / less error prone. In that case it would be:

$('td.yourClass').html('the content');
眼泪淡了忧伤 2024-10-23 10:02:11

安装 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文