相关疑难解决方法(0)

在JavaScript中创建多行字符串

我在Ruby中有以下代码.我想将此代码转换为JavaScript.什么是JS中的等效代码?

text = <<"HERE"
This
Is
A
Multiline
String
HERE
Run Code Online (Sandbox Code Playgroud)

javascript string heredoc multiline

2412
推荐指数
27
解决办法
137万
查看次数

将换行符插入javascript字符串

我看了这个提问/回答这一个,但我不能让它在我的情况下工作.

我正在从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没有单引号.我无法让它发挥作用.

javascript newline insert

7
推荐指数
1
解决办法
4万
查看次数

使用css集成样式标记

我尝试<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/ …

html javascript css jquery

6
推荐指数
1
解决办法
196
查看次数

将换行符字符(即\ r \n)附加到发布请求中发送的表单字段

我正在编写一些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)

html javascript newline http-post textinput

2
推荐指数
1
解决办法
1553
查看次数

标签 统计

javascript ×4

html ×2

newline ×2

css ×1

heredoc ×1

http-post ×1

insert ×1

jquery ×1

multiline ×1

string ×1

textinput ×1