JavaScript 用getElementById获取了 带换行的textarea,读取不到\n

明明换了行了
用var 定义一个变量来接收字符串
调试看,却没有\n 只把我的字符全合并到一起了
空格是有效的,就是换行接收不到\n

6个回答

<br> //换行转回车<br> var haha=document.getElementById(&quot;SendTextArea&quot;).value;<br> haha=haha.replace(&#39;<br />&#39;,&#39;/n&#39;);<br> document.getElementById(&quot;SendTextArea&quot;).value=haha;<br>

看看有没有\r呢?

qq_31461149
qq_31461149 明明敲了回车,读到的字符串没有任何/r/n之类的,但是空格会照常读取到" ",别人电脑也可以读到,我估计是配置的问题,但不知道问题在哪里
4 年多之前 回复

你的textarea控件中的值,是怎么来的?需要确定textarea.value是否还换行符。

textarea的value值中如果有换行的话,获取到值是能换行的,只是没有显式的\n而已,可以测试alert(textarea.value)的话是能看到换行效果的。
实例效果:图片说明

HTML里面的换行是

haha=haha.replace('
','/n');

特殊字符应该需要转义的

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
getElementById获取不到对象

求大侠指点,为什么以下代码 getElementById获取不到 id='myshow'的div? ``` <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> <script language="javascript" type="text/javascript"> var el=document.getElementById("myshow"); el.innerHTML="dfsdfdf" </script> </head> <body> <div id="myshow"></div> </body> </html> ```

在javascript中获取textarea值

<div class="post-text" itemprop="text"> <p>Iam using Tinymce Editor for creating some content.I used textarea for getting tinymce editor.</p> <p>For edting i have used this code</p> <pre><code>&lt;textarea id="page_content_id" name="page_content"&gt;&lt;?php echo $page_content;?&gt;&lt;/textarea&gt; </code></pre> <p>So the saved value will be in tiny mce editor.If i add something to the editor how i can get the values in javascript using </p> <pre><code>document.getElementById("page_content_id").value </code></pre> <p>This wont give the new value.How i can get the entire value.</p> </div>

getelementById获取不到页面元素

![图片说明](https://img-ask.csdn.net/upload/201903/14/1552548011_113681.png) ![图片说明](https://img-ask.csdn.net/upload/201903/14/1552548019_5727.png) <br><br> 获取不到页面的元素,然而同时获取的“cName”就能获取的到。尝试过将js放在最后加载,但是仍获取不到元素。 </br> **前端页面** <br> ``` <div class="modal-body"> <ul id="BranchType" class="nav nav-tabs"> <li class="active" id="applyMergeLi "> <a id="applyMergeA" href="#ApplyMerge" onclick=setCookieApplyMerge() data-toggle="tab">申请合入</a> </li> <li id="applyPublishLi " class="active1" > <a id="applyPublisA" href="#ApplyPublish" onclick=setCookieApplyPublish() data-toggle="tab">申请发布</a> </li> <li id="mergeReviewLogLi" class="active2"> <a id="mergeReviewLogA" href="#MergeReviewLog" onclick=setCookieMergeReviewLog() data-toggle="tab">合入审批记录</a> </li> <li id="publishReviewLogLi" class="active3" > <a id="publishReviewLogA" href="#PublishReviewLog" onclick=setCookiePublishReviewLog() data-toggle="tab">发布审批记录</a> </li> </ul> ``` </br> **后台common.js** <br> ``` function hasClass( elementOne,cName ) { if (className==null){ return false; } return !!elementOne.className.match( new RegExp( "(\\s|^)" + cName + "(\\s|$)") ); // ( \\s|^ ) 判断前面是否有空格 (\\s | $ )判断后面是否有空格 两个感叹号为转换为布尔值 以方便做判断 } function addClass( elementOne,cName ) { if( !hasClass( elementOne,cName ) ){ elementOne.className += " " + cName; }; } function removeClass( elementOne,cName ) { if( hasClass( elementOne,cName ) ){ elementOne.className = elementOne.className.replace( new RegExp( "(\\s|^)" + cName + "(\\s|$)" )," " ); // replace方法是替换 }; } ``` <br> **方法调用部分** <br> ``` function onloadApplyPage() { var applyInfoPage = getCookie("applyInfoPage"); var applyMergeLi = document.getElementById("applyMergeLi"); var applyPublishLi = document.getElementById("applyPublishLi"); var mergeReviewLogLi = document.getElementById("mergeReviewLogLi"); var publishReviewLogLi = document.getElementById("publishReviewLogLi"); var ApplyMerge = document.getElementById("ApplyMerge"); var ApplyPublish = document.getElementById("ApplyPublish"); var MergeReviewLog = document.getElementById("MergeReviewLog"); var PublishReviewLog = document.getElementById("PublishReviewLog"); if(applyInfoPage==1) { //为这个类移除属性 addClass(applyMergeLi,"active"); removeClass(applyPublishLi,"active"); removeClass(mergeReviewLogLi,"active"); removeClass(publishReviewLogLi,"active"); $("#applyMergeA").attr("aria-expanded","true"); $("#applyPublishA").attr("aria-expanded","false"); $("#mergeReviewLogA").attr("aria-expanded","false"); $("#publishReviewLogA").attr("aria-expanded","false"); addClass(ApplyMerge,"active"); removeClass(ApplyPublish,"active"); removeClass(MergeReviewLog,"active"); removeClass(PublishReviewLog,"active"); } if(applyInfoPage==2) { //为这个类移除属性 removeClass(applyMergeLi,"active"); addClass(applyPublishLi,"active"); removeClass(mergeReviewLogLi,"active"); removeClass(publishReviewLogLi,"active"); $("#applyMergeA").attr("aria-expanded","false"); $("#applyPublishA").attr("aria-expanded","true"); $("#mergeReviewLogA").attr("aria-expanded","false"); $("#publishReviewLogA").attr("aria-expanded","false"); removeClass(ApplyMerge,"active"); addClass(ApplyPublish,"active"); removeClass(MergeReviewLog,"active"); removeClass(PublishReviewLog,"active"); } if(applyInfoPage==3) { //为这个类移除属性 removeClass(applyMergeLi,"active"); removeClass(applyPublishLi,"active"); addClass(mergeReviewLogLi,"active"); removeClass(publishReviewLogLi,"active"); $("#applyMergeA").attr("aria-expanded","false"); $("#applyPublishA").attr("aria-expanded","false"); $("#mergeReviewLogA").attr("aria-expanded","true"); $("#publishReviewLogA").attr("aria-expanded","false"); removeClass(ApplyMerge,"active"); removeClass(ApplyPublish,"active"); addClass(MergeReviewLog,"active"); removeClass(PublishReviewLog,"active"); } if(applyInfoPage==4) { //为这个类移除属性 removeClass(applyMergeLi,"active"); removeClass(applyPublishLi,"active"); removeClass(mergeReviewLogLi,"active"); addClass(publishReviewLogLi,"active"); $("#applyMergeA").attr("aria-expanded","false"); $("#applyPublishA").attr("aria-expanded","false"); $("#mergeReviewLogA").attr("aria-expanded","false"); $("#publishReviewLogA").attr("aria-expanded","true"); removeClass(ApplyMerge,"active"); removeClass(ApplyPublish,"active"); removeClass(MergeReviewLog,"active"); addClass(PublishReviewLog,"active"); } } ```

使用javascript从textarea获取原始文本并将其发送到PHP

<div class="post-text" itemprop="text"> <p>I have a textarea where I put some C++ code, then I get that code with javascript and send it to a PHP script via AJAX to be processed. The problem is that the code gets corrupted in the way.</p> <p>Here is my code:</p> <pre><code>function showResult() { var code = document.getElementById('code').value; var input = document.getElementById('input').value; if (code != '') { var xmlhttp; if (window.XMLHttpRequest) { xmlhttp = new XMLHttpRequest(); } xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4 &amp;&amp; xmlhttp.status == 200) { document.getElementById('result').innerHTML = xmlhttp.responseText; } } xmlhttp.open('GET', 'ideone.php?code=' + code + '&amp;input=' + input, true); xmlhttp.send(); } } </code></pre> <p>PHP:</p> <pre><code>&lt;?php echo 'Code: '.$_GET['code']; // Empty string ?&gt; </code></pre> </div>

从函数输入到Javascript插入带换行符的单词

<div class="post-text" itemprop="text"> <p>I have a condition below. pop function in button input has line 1 followed by newline Line2. When I click on button to javascript it pops error " Unexpected token ILLEGAL " in Console.</p> <p>Value inside pop() of button is generated dynamically. I get this error only if I have a new line char in the input text.</p> <pre><code>&lt;script type='text/javascript'&gt; function pop(valu) { alert("here"+valu); document.getElementById('box').innnerHTML = valu; } &lt;/script&gt; &lt;button onclick="pop('Line 1 Line 2')"&gt; Click &lt;/button&gt; &lt;textarea id='box'&gt;&lt;/textarea&gt; </code></pre> <p>Backend is PHP. </p> <p>Is there any way to achieve this on foreground ? or should I make any changes of inserting values to DB ? </p> <p>I directly store the values in DB with newline character. </p> </div>

带换行符的文本通过Ajax / JavaScript返回文本中的

<div class="post-text" itemprop="text"> <p>Code that works fine except for the issue of passing a value back and forth between JavaScript, Ajax, and PHP. Using TinyMCE as the editor, when I add a paragraph break in the text, save the data (passing it through JavaScript/Ajax and PHP to do so) the text appears to be okay. Here's the JavaScript and Ajax code -- this works, it passes the data correctly to the PHP program when the submit button is clicked:</p> <pre><code> // save the main who's who form data: $("form#who_main").submit(function(e) { e.preventDefault(); // first thing, clear out the message div used for this (if there's anything there): document.getElementById("who_message").innerHTML = ""; // because we're using TinyMCE, need to replace value in that into the textarea // so that when JavaScript gathers the formData it is getting it from the textarea // controls (it doesn't know what to do with TinyMCE): var shortbio = tinymce.get('shortbio').getContent(); document.getElementById( "shortbio" ).value = shortbio; var user_notes = tinymce.get('user_notes').getContent(); document.getElementById( "user_notes" ).value = user_notes; var admin_notes = tinymce.get('admin_notes').getContent(); document.getElementById( "admin_notes" ).value = admin_notes; // this loads all the controls of the form rather than doing one at a time and fumbling // with the file object ...: var formData = new FormData(this); // ajax call to attempt to upload and save the image: $.ajax ({ type: "POST", url: "&lt;?php echo $History_html_RootPath; ?&gt;admin/AjaxCalls/who_update_main_save.php", data: formData, dataType: "json", // return value is json array processData : false, contentType: false, success: function(data) { // need to see if we have an error, if so, display it, otherwise, // we should hopefully have success ... if ( data[0].toLowerCase().includes( "error" ) ) { var errormsg = "&lt;div class='alert alert-danger'&gt;"+data+"&lt;/div&gt;"; document.getElementById("who_message").innerHTML = errormsg; return; } else { // success! // update things on screen, so we don't get confused using the data array returned // from PHP: document.getElementById("namecode").value = data[0]; document.getElementById("region").value = data[1]; document.getElementById("local").value = data[2]; document.getElementById("preferredtitle").value = data[3]; document.getElementById("shortbio").value = data[4]; tinymce.get('shortbio').setContent( data[4] ); document.getElementById("headshotphoto").value = data[5]; document.getElementById("photographername").value = data[6]; document.getElementById("photographerlink").value = data[7]; document.getElementById("user_notes").value = data[8]; tinymce.get('user_notes').setContent( data[8] ); document.getElementById("admin_notes").value = data[9]; tinymce.get('admin_notes').setContent( data[9] ); // clear out the upload file control: //document.getElementById("headshotphoto").value = ""; // change the message: var message = "&lt;div class='alert alert-success'&gt;"; message += "&lt;b&gt;Success!&lt;/b&gt; This data has been updated in the &lt;i&gt;holding&lt;/i&gt; table."; message += "&lt;/div&gt;"; document.getElementById("who_message").innerHTML = message; return; } } // end success }); // end ajax call }) // end of code associated with who_main submit </code></pre> <p>The PHP file receives the data via post, and I use the PHP function mysqli_real_escape_string() to deal with issues. The one problem with doing this is that it appears to insert backslashes for quotes (single and double), and so on. I just had a thought that <strong>might be the cause</strong> of the problem, and that is the use of this function, I am not sure. I will test it, but in the meantime. ... I save the data to the table and all is good. If there's a paragraph break, the proper tags are saved out into the table. &lt;p&gt;Some text&lt;/p&gt;&lt;p&gt;More text 'quoted text'&lt;/p&gt;</p> <p>When I pass the data back using JSON encoding:</p> <pre><code>$returndata = array(); $returndata[0] = $namecode; $returndata[1] = $region; $returndata[2] = $local; $returndata[3] = $preferredtitle; $returndata[4] = $shortbio; $returndata[5] = $photo_file; $returndata[6] = $photographername; $returndata[7] = $photographerlink; $returndata[8] = $user_notes; $returndata[9] = $admin_notes; // done-done: echo json_encode( $returndata ); return; </code></pre> <p>The code above (the javascript/Ajax code) comes back looking like: &lt;p&gt;Some text&lt;/p&gt; &lt;p&gt;More text \'quoted text\'&lt;/p&gt;</p> <p>I need to not have the and \' (or \") showing up in my text. If I were to save it again like that it gets weirder as the backslashes get duplicated and more. I am sure there's some <em>thing</em> I am missing, but I don't know what it is. This is making me crazy because everything else works exactly as I need it to.</p> <p><strong>NOTE</strong> Added code that I have attempted to use, in PHP, to deal with "escapes", it works for single and double quotes, but not for the characters -- instead it just strips out the backslash:</p> <pre><code>function remove_escapes( $string ) { $string = str_replace ( "\'", "&amp;#039;", $string ); // convert single quote $string = str_replace ( "\"", "&amp;quot;", $string ); // convert double-quote $string = str_replace ( " ", "", $string ); // remove $string = str_replace ( "\\", "", $string ); // remove slash // anything else giving us heartburn? return $string; } // eof: remove_escapes() </code></pre> <p>If I use this with the json array, I get the letters rn inserted between paragraphs:</p> <pre><code>$returndata[8] = remove_escapes( $user_notes ); $returndata[9] = remove_escapes( $admin_notes ); </code></pre> </div>

带有textarea的GetElementByID

<div class="post-text" itemprop="text"> <p>I tried to send form data through TinyMCE, but script sends old value, not new. Form code:</p> <pre><code>&lt;form&gt; &lt;textarea id="tml" name="template_content" class="editor_large"&gt;{$template_content|escape}&lt;/textarea&gt; &lt;/form&gt; &lt;input class="button_green button_save" type="button" name="save" value="Save" /&gt; </code></pre> <p>JS code:</p> <pre><code>$(function() { // Saving AJAX code function save() { $('#tml').css('background-color','#e0ffe0'); content=document.getElementById("tml").innerHTML $.ajax({ type: 'POST', url: 'ajax/save_template.php', data: {'content': content, 'theme':'{/literal}{$theme}{literal}', 'template': '{/literal}{$template_file}{literal}', 'session_id': '{/literal}{$smarty.session.id}{literal}'}, success: function(data){ $('#tml').animate({'background-color': '#000000'}); }, dataType: 'json' }); } // Press Save $('input[name="save"]').click(function() { save(); }); // ctrl+s var isCtrl = false; var isCmd = false; $(document).keyup(function (e) { if(e.which == 17) isCtrl=false; if(e.which == 91) isCmd=false; }).keydown(function (e) { if(e.which == 17) isCtrl=true; if(e.which == 91) isCmd=true; if(e.which == 83 &amp;&amp; (isCtrl || isCmd)) { save(); e.preventDefault(); } }); }); </code></pre> <p>As i think, my script also must change color via css, but it also didnt. Save_template.php file:</p> <pre><code>&lt;?php session_start(); chdir('../..'); require_once('api/Simpla.php'); $simpla = new Simpla(); if(!$simpla-&gt;managers-&gt;access('design')) return false; // Проверка сессии для защиты от xss if(!$simpla-&gt;request-&gt;check_session()) { trigger_error('Session expired', E_USER_WARNING); exit(); } $content = $simpla-&gt;request-&gt;post('content'); $template = $simpla-&gt;request-&gt;post('template'); $theme = $simpla-&gt;request-&gt;post('theme', 'string'); if(pathinfo($template, PATHINFO_EXTENSION) != 'tpl') exit(); $file = $simpla-&gt;config-&gt;root_dir.'design/'.$theme.'/html/'.$template; if(is_file($file) &amp;&amp; is_writable($file) &amp;&amp; !is_file($simpla-&gt;config-&gt;root_dir.'design/'.$theme.'/locked')) file_put_contents($file, $content); $result= true; header("Content-type: application/json; charset=UTF-8"); header("Cache-Control: must-revalidate"); header("Pragma: no-cache"); header("Expires: -1"); $json = json_encode($result); print $json; </code></pre> <p>In my opinion, problem hides in GetElementByID</p> </div>

在document.getElementById中使用变量

<div class="post-text" itemprop="text"> <p>I'd like to use a php variable instead of <code>#particles</code> in the below given code.</p> <p>I tried using:</p> <pre><code>$(" . json_encode($paramnameid) . ").particleground({ </code></pre> <p>but that didn't work.</p> <pre><code>$script = "&lt;script type='text/javascript'&gt; document.addEventListener('DOMContentLoaded', function () { particleground(document.getElementById('#particles'), { dotColor: " . json_encode($dotcolor) . ", lineColor: " . json_encode($linecolor) . " }); }, false); &lt;/script&gt;"; </code></pre> <p>How can I do this?</p> </div>

document.getElementById()获取的值不对

``` <html> <head> <title>控制首页</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <link rel="stylesheet" type="text/css" href="css/table.css"> </head> <script type="text/javascript"> function checkState() { var bc_id = document.getElementById("bc_id").value; var bc_state = document.getElementById("bc_state").value; alert("bc_id======="+bc_id+"******************bc_state========"+bc_state); document.form1.action = 'AutoBatchConfig_updateAutoBatchState.action?bc_id='+bc_id+'&bc_state'+bc_state; } </script> <body> <center> <form action="" method="post" id="form1" name="form1"> <div style="overflow-x: auto; overflow-y: auto; width: auto; height: 490px"> <table cellspacing="0"> <tr> <td style="width:778px;">服 务 拨 测 控 制 台</td> </tr> </table> <table cellspacing="0"> <tr style="text-align: center;"> <th scope="col" style="width:150px">序列</th> <th scope="col" style="width:400px">控制项</th> <th scope="col" style="width:200px">任务状态</th> </tr> <s:iterator value="#request.autoBatchConfigList" var="rel" status="st"> <tr> <th scope="col" style="width:150px"> <s:property value="#rel.bc_id" /> </th> <th scope="col" style="width:400px"> <s:property value="#rel.bc_name" /> </th> <th scope="col" style="width:200px"> <s:if test="%{#rel.bc_state == \"1\"}"> <input type="image" src="images/stop.gif" onclick="checkState()" title="<s:property value="#rel.bc_id"/>"/> </s:if> <s:else> <input type="image" src="images/running.gif" onclick="checkState()" title="<s:property value="#rel.bc_id"/>"/> </s:else> <input type="text" id="bc_id" value="<s:property value="#rel.bc_id"/>" style="width:50px;"/> <input type="text" id="bc_state" value="<s:property value="#rel.bc_state"/>" style="width:50px;"/> </th> </tr> </s:iterator> </table> </div> </form> </center> </body> </html> ``` ![图片说明](https://img-ask.csdn.net/upload/201512/07/1449476938_908553.png) 点击序列“3”后的小红色图片 ![图片说明](https://img-ask.csdn.net/upload/201512/07/1449476950_934905.png) 结果应该是bc_id=3,bc_state=1才对

尝试在JavaScript中发出警报时,Textarea内容会产生错误

<div class="post-text" itemprop="text"> <p>I created a HTML form that submits to a PHP script. The script should just write content of a dynamically created <code>input</code> element as an argument to <code>alert</code> JavaScript function. The input is from WYSIWYG editor (CKEditor).</p> <p>When I input multiple lines of text in the editor and I press the submit button of the form, Firebug shows that the <code>woa.php</code> (form’s target) produces an error:</p> <pre class="lang-none prettyprint-override"><code>SyntaxError: unterminated string literal alert("&lt;p&gt;Hi watsup&lt;p&gt; </code></pre> <p>How can I solve this?</p> <p>Page with form:</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;script src="./ckeditor/ckeditor.js"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;form method="post" action="woa.php" id="myForm"&gt; &lt;textarea name='editor1'&gt;&lt;/textarea&gt; &lt;script&gt; window.onload = function() { var textContent = CKEDITOR.replace('editor1'); var button = document.getElementById("button"); button.onclick = function(event) { event.preventDefault(); var userInput = document.createElement("input"); userInput.type = "hidden"; userInput.name = "userInput"; userInput.value = textContent.getData(); var myForm = document.getElementById("myForm"); myForm.appendChild(userInput); } } &lt;/script&gt; &lt;button id="button"&gt;finish edit&lt;/button&gt; &lt;button&gt;save&lt;/button&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Target of the form (<code>woa.php</code>):</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;script&gt; alert("&lt;?php echo $_POST['userInput']; ?&gt;"); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> </div>

使用getElementById获取类型错误

<div class="post-text" itemprop="text"> <p>I am using the following code to make a call to another script:</p> <pre><code>function savecoupon&lt;?php echo $r['id']; ?&gt;() { var listingid = document.savecouponform&lt;?php echo $r['id']; ?&gt;.listingid.value; http.open('get', 'script/save_coupon.php?listingid='+listingid+''); http.onreadystatechange = handleResponse; http.send(null); } function handleResponse() { if(http.readyState == 4){ response = http.responseText; alert(response); document.getElementById(response).innerHTML = "Saved"; } } </code></pre> <p>The <code>alert(response)</code> is showing the proper results, which is the element id of the div that I am replacing. But for some reason, when I put the response into the getElementById I get the following error in firebug:</p> <pre><code>TypeError: document.getElementById(...) is null document.getElementById(response).innerHTML = "Saved"; </code></pre> <p>If I replace the innerHTML command with <code>document.getElementById("savecouponarea1327").innerHTML = "Saved";</code> everything works as it is supposed to. How come the response is not being read in the getElementById?</p> </div>

document.getelementbyid()无法获取元素

情况如下 我想获取的元素位于跨域iframe中,使用谷歌浏览器的开发者工具的控制台执行语句 已知的是id本身没问题,检查页面后,元素也存在 但是执行语句返回null 然后有意思的事情来了,如果我在开发者工具的Elements标签中找到这个元素,并且左键点击它一下,document.getelementbyid()就能返回元素了,不用做任何修改 这是问什么???

如何使用ajax获取文本区域数据(文本区域中的Html文件)我需要将数据发送到Php? Ajax没有发送我的文本区域数据?

<div class="post-text" itemprop="text"> <p>If I'm trying to send Html Data in textarea Code is failed. alert Working till Username data getting properly but ajax not sending my Data to Php server. </p> <hr> <h1>Javascript</h1> <pre><code> var username=document.getElementById( "my_text" ).value; if(username){ $.ajax({ type: 'post', url: 'checkdata.php?username=username', data: { username:username, }, success: function (response){ $( '#name_status' ).html(response); if(response=="OK"){ return true; } else{ return false; } } }); </code></pre> <h1>Html</h1> <pre><code> &lt;textarea id="my_text" &gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;Page Title&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;h1&gt;My First Heading&lt;/h1&gt; &lt;p&gt;My first paragraph.&lt;/p&gt; &lt;/body&gt; &lt;/html&gt; &lt;/textarea&gt; </code></pre> </div>

使用javascript将焦点放在具有变量名称的textarea中

<div class="post-text" itemprop="text"> <p>I have a site that lists several upcoming events, and each event has a comment button to leave comments. It looks like this (it's in swedish, but I think you can figure out the structure):</p> <p><img src="https://i.stack.imgur.com/trals.png"><br><sub>(source: <a href="http://www.shipit.se/dump/event.png" rel="nofollow noreferrer">shipit.se</a>)</sub><br></p> <p>The div containing the textarea for writing the comment is initially hidden, and when clicking the 'comment'-icon it is displayed using the following javascript:</p> <pre><code>&lt;script language="javascript" type='text/javascript'&gt; function showhide_comment(comment_id, change_id) { if (document.getElementById(comment_id).style.display == 'none') { if (document.getElementById(change_id).style.display == 'block') { document.getElementById(change_id).style.display = 'none'; document.getElementById(comment_id).style.display = 'block'; document.getElementById(change_id).style.display = 'block'; } else { document.getElementById(comment_id).style.display = 'block'; } } else { if (document.getElementById(change_id).style.display == 'block') { document.getElementById(change_id).style.display = 'none'; document.getElementById(comment_id).style.display = 'none'; document.getElementById(change_id).style.display = 'block'; } else { document.getElementById(comment_id).style.display = 'none'; } } } </code></pre> <p>The script contains a hack to display the hidden div correctly in IE when another (initially hidden) div is also displayed in which changes can be made to the event. But never mind that.</p> <p>The php-code to display the comment form looks like this:</p> <pre><code>//Comment form, initially hidden echo "&lt;div id=\"comment" . $row-&gt;id . "\" class=\"submit-comment\" style=\"display: none\"&gt;"; echo "&lt;form name=\"make_comment\" method=\"post\" action=\"submit_comment.php\"&gt;"; echo "Kommentar:&lt;br/&gt;"; echo "&lt;textarea name=\"comment\" class=\"comment\" rows=\"0\" cols=\"0\"&gt;&lt;/textarea&gt;&lt;br/&gt;"; echo "&lt;input type=\"hidden\" name=\"event_id\" value=\"$row-&gt;id\"/&gt;"; echo "&lt;input class=\"comment\" type=\"submit\" name=\"submit_comment\" value=\"Skicka\" /&gt;"; echo "&lt;/form&gt;"; echo "&lt;/div&gt;"; </code></pre> <p>This code lies inside a loop which displays all upcoming events that are stored in a mySQL database. As can be seen, the divs are given variable names like comment1, comment2, etc. in order to bind the comments to the correct event. </p> <p>This is the code to display the comment-icon and linking it to the javascript:</p> <pre><code>echo "&lt;li class=\"icon-left\"&gt; &lt;a href=\"javascript:showhide_comment('comment" . $row-&gt;id . "', 'change" . $row-&gt;id . "')\"&gt; &lt;img src=\"images/comment-24x24.png\" title=\"Kommentera körning\" alt=\"Kommentera körning\" /&gt; &lt;/a&gt;&lt;/li&gt;"; </code></pre> <p>What I would like to do is to put the focus inside the correct textarea field that becomes visible when the comment-icon is clicked so that the user can start typing directly. I have tried to modify the javascript above using focus(), but I just can't get it to work. Any ideas on how I can achieve what I want?</p> <p>Thanks.</p> <p>/Linus</p> </div>

javaScript中获取获取标签的问题

目的是对下拉选框中的所有<option>标签进行操作,定义下拉选框的代码为 ``` <select id="left" multiple="true" style="width:100px" size="10"> <option>環</option> <option>芈</option> <option>琅</option> <option>琊</option> <option>爨</option> <option>甄</option> <option>槑</option> <option>夔</option> </select> ``` ``` 该文件中所有的<option>标签都在上面的<select>标签中, 对<option>进行抓取并操作的代码是 document.getElementById("toRight2").onclick=function() { arr = document.getElementById("left").options; for(i=0;i<arr.length;i++) { if(arr[i].selected) { document.getElementById("right").appendChild(arr[i]); i--; //注意:将元素添加至右边后,左边的option元素个数就减少1,所移动元素之后的标签索引减1, //为了仍然能够遍历所有的元素,应手动将当前索引值减一。 } } } ``` ```但是如果将上面获取标签的语句换成 arr = document.getElementsByTagName("option"); 运行时触发事件,则浏览器会无响应进入卡死状态,请问这是什么原因啊?这两种获取方式有什么不同吗?通过打印这两种方式获取的数组,我发现方式一得到的数组类型是[object HTMLOption Collection ]而方式二得到的数组类型是[object HTML Collection] 求大神指点 ```

一个textarea的内容复制到不同页面的另一个textarea

<div class="post-text" itemprop="text"> <p>I have two pages <code>index.php</code> and <code>search.php</code>, both have a search box. If the user enters the name to be searched in the <code>index.php</code> Textarea and clicks on submit button the content of the Textarea should be loaded in the <code>search.php</code> page.</p> <p>index.php</p> <pre><code> &lt;form action="search.php" method="post"&gt; &lt;div&gt; &lt;input type="text" name="query_data" placeholder="Who would you like to find today?"&gt; &lt;/div&gt; &lt;div&gt; &lt;input type="submit" name="submit" value="SEARCH"&gt;&lt;/input&gt; &lt;/div&gt; &lt;/form&gt; </code></pre> <p>search.php</p> <pre><code>&lt;div&gt; &lt;div&gt; &lt;input type="text" name="search" id="search" placeholder= &lt;?php echo $_POST["query_data"]; ?&gt; &gt; &lt;/div&gt; &lt;div&gt; &lt;input type="submit" name="submit" value="SEARCH" onclick="func()"&lt;/input&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>I want the name searched in the <code>index.php</code> page to be the <strong>placeholder</strong> in the <code>search.php</code> page. The user would have to click on the search button of the <code>search.php</code> page to load the function <code>func()</code> and get the answers. This code is wrong and is not working. It is giving an error that the <em>query is undefined</em>. Please Help! Thanks a lot!</p> <p>I have added the Javascript file also. It has Ajax and is getting the right result when used on the search.php page. The problem is not with the Javascript though!</p> <pre><code>&lt;script type="text/javascript"&gt; function func() { var tosearch=document.getElementById("search").value; if(tosearch==="") print("&lt;center&gt;&lt;b&gt;Nothing To Search For!!&lt;/b&gt;&lt;/center&gt;"); else {$.ajax({ type: 'post', url: 'page2.php', data: {'tosearch' : tosearch}, dataType: "html", success: function (result) { print(result); } }); } } function print(result){ document.getElementById("output").innerHTML=result; } </code></pre> <p></p> </div>

如何在javascript变量中获取php函数返回值

<div class="post-text" itemprop="text"> <p>How can I use <code>return</code> a value from a PHP function to a JavaScript variable? Example:</p> <p>PHP:</p> <pre><code>// Destination folder for downloaded files $date = date('m.d.y'); mkdir("uploads/" . $date, 0777, true); $upload_folder = 'uploads/' . $date; // If the browser supports sendAsBinary () can use the array $ _FILES if(count($_FILES)&gt;0) { if( move_uploaded_file( $_FILES['upload']['tmp_name'] , $upload_folder.'/'.$_FILES['upload']['name'] ) ) { echo 'done'; } exit(); } else if(isset($_GET['up'])) { // If the browser does not support sendAsBinary () if(isset($_GET['base64'])) { $content = base64_decode(file_get_contents('php://input')); } else { $content = file_get_contents('php://input'); } $headers = getallheaders(); $headers = array_change_key_case($headers, CASE_UPPER); if(file_put_contents($upload_folder.'/'.$headers['UP-FILENAME'], $content)) { echo 'done'; } exit(); } $pathinfo = realpath($upload_folder); return $pathinfo; </code></pre> <p>Javascript</p> <pre><code>this.MakeRequest = function() { var somename = "somenameTest"; var xmlHttp = getXMLHttp(); xmlHttp.onreadystatechange = function() { if(xmlHttp.readyState == 4) { HandleResponse(xmlHttp.responseText); } } xmlHttp.open("GET", "download.php", true); xmlHttp.send(); } function HandleResponse(response) { document.getElementById('output').innerHTML = response; **var x = php return varible** } </code></pre> </div>

textarea 动态修改overflow属性问题

<html><head> <script type="text/javascript" language="javascript"> function TextAreaRow() { var obj=document.getElementById("textarea"); var rng=obj.createTextRange(); var h=rng.boundingHeight; rng.move('character',1) var mh=rng.boundingHeight; var dd=(h/mh).toFixed(0); if(dd>7){ [color=red]document.getElementById("textarea").style.overflow='';[/color] } document.getElementById("showRow").value=(h/mh).toFixed(0); } </script> </head><body onresize="TextAreaRow()" onkeyup="TextAreaRow()" onload="TextAreaRow()"> <textarea id="textarea" cols="49" rows="7" style="overflow-y:hidden"> sdf sd f sfasf </textarea> 行数:<input type="text" id="showRow"> </body></html> 当dd 大于7时修改textarea的overflow属性([color=red]把style="overflow-y:hidden"这个属性去掉[/color])?万分感谢!!!

如何使用Javascript获取行位置?

<div class="post-text" itemprop="text"> <p>I have a little problem... In my PHP-Code the user should be able to add a row to a HTML-Table by clicking on a button on the right side of the row. Then the new row should be displayed under the row, where the button is shown. To do that, I need to get the row-positon, but I don't know how.</p> <p>I've tried this:</p> <p></p><div class="snippet" data-lang="js" data-hide="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code>function deleteRow(rowNumber) { document.getElementById("Angebotsformular").deleteRow(rowNumber); } function addRow(rowNumber) { var table = document.getElementById("Angebotsformular"); var row = table.insertRow(rowNumber); //THIS IS THE VALUE I NEED TO FIND var cell1 = row.insertCell(0); var cell2 = row.insertCell(1); var cell3 = row.insertCell(2); var cell4 = row.insertCell(3); var posnr = document.createElement("input"); var posorder = document.createElement("input"); var unit = document.createElement("input"); posnr.type = "text"; posnr.name = "position"; posnr.size = 6; posorder.type = "text"; posorder.name = "order"; posorder.size = 6; unit.type = "text"; unit.name = "unit"; unit.size = 6; cell1.appendChild(posnr); cell2.appendChild(posorder); cell3.appendChild(unit); cell4.innerHTML('&lt;span onclick="hinzufuegen();"&gt;Add&lt;/span&gt;&lt;span onclick="loeschen();"&gt;Remove&lt;/span&gt;'); }</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code> &lt;tr&gt; &lt;td&gt;&lt;input type="text" size="6" id="position"&gt;&lt;/td&gt; &lt;td&gt;&lt;input type="text" size="6" id="order"&gt;&lt;/td&gt; &lt;td&gt;&lt;input type="text" size="6" id="unit"&gt;&lt;/td&gt; &lt;td&gt;&lt;span onclick="addRow(this);"&gt;Add&lt;/span&gt;&lt;span onclick="deleteRow(this);"&gt;Remove&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt;</code></pre> </div> </div> <p>Can you please help me with that? </p> <p>Another problem is, that the content of cell4 does not show up. Thank you all very much.</p> </div>

C/C++学习指南全套教程

C/C++学习的全套教程,从基本语法,基本原理,到界面开发、网络开发、Linux开发、安全算法,应用尽用。由毕业于清华大学的业内人士执课,为C/C++编程爱好者的教程。

定量遥感中文版 梁顺林著 范闻捷译

这是梁顺林的定量遥感的中文版,由范闻捷等翻译的,是电子版PDF,解决了大家看英文费时费事的问题,希望大家下载看看,一定会有帮助的

YOLOv3目标检测实战:训练自己的数据集

YOLOv3是一种基于深度学习的端到端实时目标检测方法,以速度快见长。本课程将手把手地教大家使用labelImg标注和使用YOLOv3训练自己的数据集。课程分为三个小项目:足球目标检测(单目标检测)、梅西目标检测(单目标检测)、足球和梅西同时目标检测(两目标检测)。 本课程的YOLOv3使用Darknet,在Ubuntu系统上做项目演示。包括:安装Darknet、给自己的数据集打标签、整理自己的数据集、修改配置文件、训练自己的数据集、测试训练出的网络模型、性能统计(mAP计算和画出PR曲线)和先验框聚类。 Darknet是使用C语言实现的轻型开源深度学习框架,依赖少,可移植性好,值得深入探究。 除本课程《YOLOv3目标检测实战:训练自己的数据集》外,本人推出了有关YOLOv3目标检测的系列课程,请持续关注该系列的其它课程视频,包括: 《YOLOv3目标检测实战:交通标志识别》 《YOLOv3目标检测:原理与源码解析》 《YOLOv3目标检测:网络模型改进方法》 敬请关注并选择学习!

sql语句 异常 Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your

在我们开发的工程中,有时候会报 [Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ------ 这种异常 不用多想,肯定是我们的sql语句出现问题,下面...

浪潮集团 往年的软件类 笔试题 比较详细的哦

浪潮集团 往年的软件类 笔试题 比较详细的哦

2019 AI开发者大会

2019 AI开发者大会(AI ProCon 2019)是由中国IT社区CSDN主办的AI技术与产业年度盛会。多年经验淬炼,如今蓄势待发:2019年9月6-7日,大会将有近百位中美顶尖AI专家、知名企业代表以及千余名AI开发者齐聚北京,进行技术解读和产业论证。我们不空谈口号,只谈技术,诚挚邀请AI业内人士一起共铸人工智能新篇章!

I2c串口通信实现加速度传感器和FPGA的交流

此代码能实现加速度传感器与FPGA之间的交流,从而测出运动物体的加速度。

Python可以这样学(第一季:Python内功修炼)

董付国系列教材《Python程序设计基础》、《Python程序设计(第2版)》、《Python可以这样学》配套视频,讲解Python 3.5.x和3.6.x语法、内置对象用法、选择与循环以及函数设计与使用、lambda表达式用法、字符串与正则表达式应用、面向对象编程、文本文件与二进制文件操作、目录操作与系统运维、异常处理结构。

微信公众平台开发入门

本套课程的设计完全是为初学者量身打造,课程内容由浅入深,课程讲解通俗易懂,代码实现简洁清晰。通过本课程的学习,学员能够入门微信公众平台开发,能够胜任企业级的订阅号、服务号、企业号的应用开发工作。 通过本课程的学习,学员能够对微信公众平台有一个清晰的、系统性的认识。例如,公众号是什么,它有什么特点,它能做什么,怎么开发公众号。 其次,通过本课程的学习,学员能够掌握微信公众平台开发的方法、技术和应用实现。例如,开发者文档怎么看,开发环境怎么搭建,基本的消息交互如何实现,常用的方法技巧有哪些,真实应用怎么开发。

机器学习初学者必会的案例精讲

通过六个实际的编码项目,带领同学入门人工智能。这些项目涉及机器学习(回归,分类,聚类),深度学习(神经网络),底层数学算法,Weka数据挖掘,利用Git开源项目实战等。

eclipseme 1.7.9

eclipse 出了新的eclipseme插件,官方有下载,但特慢,我都下了大半天(可能自己网速差)。有急需要的朋友可以下哦。。。

Spring Boot -01- 快速入门篇(图文教程)

Spring Boot -01- 快速入门篇 今天开始不断整理 Spring Boot 2.0 版本学习笔记,大家可以在博客看到我的笔记,然后大家想看视频课程也可以到【慕课网】手机 app,去找【Spring Boot 2.0 深度实践】的课程,令人开心的是,课程完全免费! 什么是 Spring Boot? Spring Boot 是由 Pivotal 团队提供的全新框架。Spring Boot...

HoloLens2开发入门教程

本课程为HoloLens2开发入门教程,讲解部署开发环境,安装VS2019,Unity版本,Windows SDK,创建Unity项目,讲解如何使用MRTK,编辑器模拟手势交互,打包VS工程并编译部署应用到HoloLens上等。

最简单的倍频verilog程序(Quartus II)

一个工程文件 几段简单的代码 一个输入一个输出(50Mhz倍频到100Mhz)

计算机组成原理实验教程

西北工业大学计算机组成原理实验课唐都仪器实验帮助,同实验指导书。分为运算器,存储器,控制器,模型计算机,输入输出系统5个章节

4小时玩转微信小程序——基础入门与微信支付实战

这是一个门针对零基础学员学习微信小程序开发的视频教学课程。课程采用腾讯官方文档作为教程的唯一技术资料来源。杜绝网络上质量良莠不齐的资料给学员学习带来的障碍。 视频课程按照开发工具的下载、安装、使用、程序结构、视图层、逻辑层、微信小程序等几个部分组织课程,详细讲解整个小程序的开发过程

面试了一个 31 岁程序员,让我有所触动,30岁以上的程序员该何去何从?

最近面试了一个31岁8年经验的程序猿,让我有点感慨,大龄程序猿该何去何从。

基于RSA通信密钥分发的加密通信

基于RSA通信密钥分发的加密通信,采用pycrypto中的RSA、AES模块实现

不同变质程度煤尘爆炸残留气体特征研究

为分析不同变质程度煤尘爆炸残留气体成分的特征规律,利用水平管道煤尘爆炸实验装置进行了贫瘦煤、肥煤、气煤、长焰煤4种不同变质程度的煤尘爆炸实验,研究了不同变质程度煤尘爆炸后气体残留物含量的差异,并对气体

设计模式(JAVA语言实现)--20种设计模式附带源码

课程亮点: 课程培训详细的笔记以及实例代码,让学员开始掌握设计模式知识点 课程内容: 工厂模式、桥接模式、组合模式、装饰器模式、外观模式、享元模式、原型模型、代理模式、单例模式、适配器模式 策略模式、模板方法模式、观察者模式、迭代器模式、责任链模式、命令模式、备忘录模式、状态模式、访问者模式 课程特色: 笔记设计模式,用笔记串连所有知识点,让学员从一点一滴积累,学习过程无压力 笔记标题采用关键字标识法,帮助学员更加容易记住知识点 笔记以超链接形式让知识点关联起来,形式知识体系 采用先概念后实例再应用方式,知识点深入浅出 提供授课内容笔记作为课后复习以及工作备查工具 部分图表(电脑PC端查看):

MySQL数据库面试题(2020最新版)

文章目录数据库基础知识为什么要使用数据库什么是SQL?什么是MySQL?数据库三大范式是什么mysql有关权限的表都有哪几个MySQL的binlog有有几种录入格式?分别有什么区别?数据类型mysql有哪些数据类型引擎MySQL存储引擎MyISAM与InnoDB区别MyISAM索引与InnoDB索引的区别?InnoDB引擎的4大特性存储引擎选择索引什么是索引?索引有哪些优缺点?索引使用场景(重点)...

软件测试2小时入门

本课程内容系统、全面、简洁、通俗易懂,通过2个多小时的介绍,让大家对软件测试有个系统的理解和认识,具备基本的软件测试理论基础。 主要内容分为5个部分: 1 软件测试概述,了解测试是什么、测试的对象、原则、流程、方法、模型;&nbsp; 2.常用的黑盒测试用例设计方法及示例演示;&nbsp; 3 常用白盒测试用例设计方法及示例演示;&nbsp; 4.自动化测试优缺点、使用范围及示例‘;&nbsp; 5.测试经验谈。

几率大的Redis面试题(含答案)

本文的面试题如下: Redis 持久化机制 缓存雪崩、缓存穿透、缓存预热、缓存更新、缓存降级等问题 热点数据和冷数据是什么 Memcache与Redis的区别都有哪些? 单线程的redis为什么这么快 redis的数据类型,以及每种数据类型的使用场景,Redis 内部结构 redis的过期策略以及内存淘汰机制【~】 Redis 为什么是单线程的,优点 如何解决redis的并发竞争key问题 Red...

手把手实现Java图书管理系统(附源码)

【超实用课程内容】 本课程演示的是一套基于Java的SSM框架实现的图书管理系统,主要针对计算机相关专业的正在做毕设的学生与需要项目实战练习的java人群。详细介绍了图书管理系统的实现,包括:环境搭建、系统业务、技术实现、项目运行、功能演示、系统扩展等,以通俗易懂的方式,手把手的带你从零开始运行本套图书管理系统,该项目附带全部源码可作为毕设使用。 【课程如何观看?】 PC端:https://edu.csdn.net/course/detail/27513 移动端:CSDN 学院APP(注意不是CSDN APP哦) 本课程为录播课,课程2年有效观看时长,大家可以抓紧时间学习后一起讨论哦~ 【学员专享增值服务】 源码开放 课件、课程案例代码完全开放给你,你可以根据所学知识,自行修改、优化

jsp+servlet入门项目实例

jsp+servlet实现班级信息管理项目

winfrom中嵌套html,跟html的交互

winfrom中嵌套html,跟html的交互,源码就在里面一看就懂,很简单

Java面试题大全(2020版)

发现网上很多Java面试题都没有答案,所以花了很长时间搜集整理出来了这套Java面试题大全,希望对大家有帮助哈~ 本套Java面试题大全,全的不能再全,哈哈~ 一、Java 基础 1. JDK 和 JRE 有什么区别? JDK:Java Development Kit 的简称,java 开发工具包,提供了 java 的开发环境和运行环境。 JRE:Java Runtime Environ...

python实现数字水印添加与提取及鲁棒性测试(GUI,基于DCT,含测试图片)

由python写的GUI,可以实现数字水印的添加与提取,提取是根据添加系数的相关性,实现了盲提取。含有两种攻击测试方法(高斯低通滤波、高斯白噪声)。基于python2.7,watermark.py为主

Xshell6完美破解版,亲测可用

Xshell6破解版,亲测可用,分享给大家。直接解压即可使用

你连存活到JDK8中著名的Bug都不知道,我怎么敢给你加薪

CopyOnWriteArrayList.java和ArrayList.java,这2个类的构造函数,注释中有一句话 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 public ArrayList(Collection&lt;? ...

相关热词 c#中如何设置提交按钮 c#帮助怎么用 c# 读取合并单元格的值 c#带阻程序 c# 替换span内容 c# rpc c#控制台点阵字输出 c#do while循环 c#调用dll多线程 c#找出两个集合不同的
立即提问