English 中文(简体)
PHP中的产出分类
原标题:Outputting jQuery in PHP, quotes issue

我有这样一米试图在购买力平价中产出:

$this->Js->buffer("
    var searchTerm = $(this).html();
    var searchId = $(this).attr( data-tag );
    $( .tags ).append( <input type= text  value= +searchTerm+  name= data[Tag][tags][ +searchId+ ]  );
");

但是,对报价和 j字变量也无动于衷。

谁能帮助?

最佳回答

You can also stop single and double quotes from tripping you up by swapping singles for doubles, e.g.:

$this->Js->buffer("
    var searchTerm = $(this).html();
    var searchId = $(this).attr( data-tag );
    $( .tags ).append( <input type="text" value= +searchTerm+  name="data[Tag][tags][ +searchId+ ]"> );
");

Would output:

var searchTerm = $(this).html();
var searchId = $(this).attr( data-tag );
$( .tags ).append( <input type="text" value= +searchTerm+  name="data[Tag][tags][ +searchId+ ]"> );
问题回答

页: 1

使用和“在输出时使用”的替罪羊

try

$this->Js->buffer("
    var searchTerm = $(this).html();
    var searchId = $(this).attr( data-tag );
    $( .tags ).append( <input type= text  value= "+searchTerm+"  name= data[Tag][tags][ "+searchId+" ] );
");
$this->Js->buffer("
    var searchTerm = $(this).html();
    var searchId = $(this).attr( data-tag );
    $( .tags ).append( <input type= text  value= +searchTerm+  name= data[Tag][tags][ +searchId+ ]  );
");

That is your code. Inside the PHP "" you must write single quotes or escape double quotes ". You have chosen to use single quotes, which is fine, except the generated JS code must also follow these rules.

$( .tags ).append( <input type= text  value= +searchTerm+  name= data[Tag][tags][ +searchId+ ]  );

问题如下: <input category=text ...>。 第一,你错过了<代码>>;- 其次,您必须使用<代码><>>>>>至text,<input category=“text”.> is okay. 但是,这将与购买力平价相冲突,因为“>>”被用于PHP的铺设。 你们不得不逃脱双面: <input category=“text.>

www.un.org/Depts/DGACM/index_french.htm 如果要直接在超文本模板中书写 Java字,就会使你节省这么多头。

If you REALLY need to put JS in your PHP files (it s bad, save it in an external file and then include it), use the heredoc syntax (or nowdoc):

$this->JS->buffer(<<<EOF
    var searchTerm = $(this).html();
    var searchId = $(this).data( tag );
    $( .tags ).append( <input type="text" value=" +searchTerm+ " name="data[Tag][tags][  +searchId+ ]" );
EOF
);




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签