我在Ruby中有以下代码.我想将此代码转换为JavaScript.什么是JS中的等效代码?
text = <<"HERE"
This
Is
A
Multiline
String
HERE
Run Code Online (Sandbox Code Playgroud) 我看了这个提问/回答和这一个,但我不能让它在我的情况下工作.
我正在从php脚本返回的json数组中构建一个名称列表.在下面的代码之后,我将goTosList字符串通过jquery放入标签中.我需要每个名字都在新的一行.
以下代码只是输出
var goTosList = '';
if (data !== 'empty') {
// Build the go tos list as a comma-separated string
$.each(data, function(index,element) {
goTosList += (element['name'] === undefined ? '' : element['name']) + '\n\r';
});
}
Run Code Online (Sandbox Code Playgroud)
我试过公正\r,\n没有单引号.我无法让它发挥作用.
我尝试<style type="text/css"></style>使用jquery 添加到头部.我试过这样的
$("<style type='text/css'></style>").appendTo("head");
Run Code Online (Sandbox Code Playgroud)
以前,我有这种类型
<style type="text/css">
img{
-moz-animation:.6s rotateRight infinite linear;
-webkit-animation:.6s rotateRight infinite linear;
}
@-moz-keyframes rotateRight{
0%{ -moz-transform:rotate(0deg); -moz-transform-origin:50% 50%; }
100%{ -moz-transform:rotate(360deg); }
}
@-webkit-keyframes rotateRight{
0%{ -webkit-transform:rotate(0deg); -webkit-transform-origin:50% 50%; }
100%{ -webkit-transform:rotate(360deg); }
}
</style>
Run Code Online (Sandbox Code Playgroud)
当我用这样的jquery尝试这个时,上面的样式工作:
$("<style type='text/css'>img{
-moz-animation:.6s rotateRight infinite linear;
-webkit-animation:.6s rotateRight infinite linear;
}
@-moz-keyframes rotateRight{
0%{ -moz-transform:rotate(0deg); -moz-transform-origin:50% 50%; }
100%{ -moz-transform:rotate(360deg); }
}
@-webkit-keyframes rotateRight{
0%{ -webkit-transform:rotate(0deg); -webkit-transform-origin:50% 50%; }
100%{ -webkit-transform:rotate(360deg); }
}</style>").appendTo("head");
Run Code Online (Sandbox Code Playgroud)
但我在编辑器本身得到错误.这是照片
我想我搞砸了一些东西:(
http://jsfiddle.net/jSvUE/ …
我正在编写一些Web表单,用于测试学生编写的服务器作为练习.有些服务器不像规范工作那样完全符合规范.将Windows新行字符(即\r\n)附加到POST浏览器生成的请求会很有用,因为有些服务器正在执行ReadLine而不是使用Content-Length:标头计数.
我正在寻找生成以下请求(来自IE):
POST /Brian HTTP/1.1
Accept: text/html, application/xhtml+xml, */*
Accept-Language: en-GB
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate
Host: localhost:43
Content-Length: 8
DNT: 1
Connection: Keep-Alive
Cache-Control: no-cache
location
Run Code Online (Sandbox Code Playgroud)
但是追加\r\n到最后.到目前为止,我这样做的尝试是:
<form>
Username: <input type="text" name="url" id="url4"
onChange="document.getElementById('update4').setAttribute('action',
'http://localhost:43/' + document.getElementById('url4').value);"> </input>
</form>
<form id="update4" method="post" action="http://localhost:43/">
Location: <input type="text" name="isindex" id="location5"
onChange="document.getElementById('location5').value =
document.getElementById('location5').value + '\\\r\\\n'"> </input>
<input id="mysubmit3" type="submit" value="go" ></input> …Run Code Online (Sandbox Code Playgroud)