Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/414.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
textarea的值不会用javascript getElementById更新_Javascript_Html - Fatal编程技术网

textarea的值不会用javascript getElementById更新

textarea的值不会用javascript getElementById更新,javascript,html,Javascript,Html,我有以下表格: <label>Subtitle:</label><br> <input required type="text" id="articleSubtitle" size="50" value="<?php somePhp Code here?>" /> <label>Date:</label><br> <input required type="date" id="arti

我有以下表格:

<label>Subtitle:</label><br>
  <input required type="text" id="articleSubtitle" size="50" value="<?php somePhp Code here?>" />

<label>Date:</label><br>
  <input required type="date" id="articleDate" size="48" value="<?php somePhp Code here?>" />

<label>Article:</label><br>
  <textarea required name="articleText" rows="10" cols="50" id="articleText" class="showEditor"><?php 
                    ignoreThis ?></textarea>
问题如下: javascript代码可以更改字幕的值,但无法更改日期字段或文本区域值


如果我将输入类型从“日期”更改为“文本”,它会工作。即使我忽略了这一点,我仍然无法更改文本区域。我做错了什么?

日期值的格式应该是
YYYY-MM-DD
,而不是
MM/DD/YYYY
,这样可以解决第一个问题

见:供参考

我无法重现第二个问题,您可以看到我的代码示例,它与您提供的相同

var subtitle=document.getElementById(“articleSubtitle”);
var articleDate=document.getElementById(“articleDate”);
var articleText=document.getElementById(“articleText”);
subtitle.value=“”;
articleDate.value='2016-02-12';
articleText.value=“111111”
副标题:

问题:

  • 在呈现组件之前,您正在访问该组件,以便使变量为空。您可以使用
    调试器

    var subtitle = document.getElementById("articleSubtitle");
    var articleDate = document.getElementById("articleDate");
    var articleText = document.getElementById("articleText");
    
  • 第二个,如上所述,是article日期变量的日期格式。 变量应为YYYY-MM-DD

    一个简单的Javascript代码

     <html>
     <head>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js">     </script>  
    
    
    <script>
    function changeval(){
    var subtitle = document.getElementById("articleSubtitle");
    var articleDate = document.getElementById("articleDate");
    var articleText = document.getElementById("articleText");
    subtitle.value = "123";
    articleDate.value = "2015/16/16";
    articleText.value = "xyz";
    }
    
    </script>
    
    </head>
    <body>   
    <label>Subtitle:</label><br>
      <input required type="text" id="articleSubtitle" size="50" value="xyz" />
    
    <label>Date:</label><br>
      <input required type="date" id="articleDate" size="48" value="16/16/2015" />
    
    <label>Article:</label><br>
      <textarea required name="articleText" rows="10" cols="50" id="articleText" class="showEditor">vasim vanzara</textarea>
    <button value="Changevalue" onclick="changeval()"/>
    
    </body>
    </html>
    
    
    函数changeval(){
    var subtitle=document.getElementById(“articleSubtitle”);
    var articleDate=document.getElementById(“articleDate”);
    var articleText=document.getElementById(“articleText”);
    subtitle.value=“123”;
    articleDate.value=“2015/16/16”;
    articleText.value=“xyz”;
    }
    副标题:
    日期:
    文章:
    瓦西姆·万扎拉

  • 你能提供更多的代码吗?这是全部代码。php元素显然不起作用,“与textarea的id和名称相同。”这没关系。我已经更改了textarea的名称,但仍然不起作用。日期的格式仍然不影响它。很抱歉是的,那个正在工作。请尝试,上面的代码。@VasimVanzara感谢您指向它。我检查过你是对的。只是认为名称和id位于同一名称空间可能会引起一些问题…日期现在生效了,谢谢!:文本区对我来说不是那么容易。你说我在渲染前访问组件s。好啊但是,为什么其他一切都可以改变,而不是这个呢?我也试过你的代码,什么也没试过/好啊我之前没有提到的是,tinyMCE wyswyg编辑器应用于textarea。我把它拆了,现在它可以工作了。我想我应该先去他们的网站,看看到底是什么!谢谢大家!:)
     <html>
     <head>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js">     </script>  
    
    
    <script>
    function changeval(){
    var subtitle = document.getElementById("articleSubtitle");
    var articleDate = document.getElementById("articleDate");
    var articleText = document.getElementById("articleText");
    subtitle.value = "123";
    articleDate.value = "2015/16/16";
    articleText.value = "xyz";
    }
    
    </script>
    
    </head>
    <body>   
    <label>Subtitle:</label><br>
      <input required type="text" id="articleSubtitle" size="50" value="xyz" />
    
    <label>Date:</label><br>
      <input required type="date" id="articleDate" size="48" value="16/16/2015" />
    
    <label>Article:</label><br>
      <textarea required name="articleText" rows="10" cols="50" id="articleText" class="showEditor">vasim vanzara</textarea>
    <button value="Changevalue" onclick="changeval()"/>
    
    </body>
    </html>