2014-10-10 101 views
0

我試圖指派以下的PHP變量:分配JavaScript彈出HTML鏈接到PHP變量

[<a href='"'javascript:pop_booking_item_add({ID})'"'>Add New Item</a>] 

我已經試過這樣:

$add_button = "[<a href='"'javascript:pop_booking_item_add({ID})'"'>Add New Item</a>]"; 

但我收到錯誤消息:

錯誤:語法錯誤,意想不到的 '' 的javascript:pop_booking_item_a」(T_CONSTANT_ENCAPSED_STRING)

我想我需要逃避報價,但我不知道如何?

回答

2

這應該工作:

$add_button = "[<a href='javascript:pop_booking_item_add({ID})'>Add New Item</a>]";

$add_button = "[<a href=\"javascript:pop_booking_item_add({ID})\">Add New Item</a>]";

+0

謝謝你的幫忙! – 2014-10-10 12:37:55

1

&quot;是混合HTML/javascript中的'"的有效替代。你有沒有試過用:

$add_button = "[<a href=&quot;javascript:pop_booking_item_add({ID});&quot;>Add New Item</a>]"; 
0

是不是更好做這樣的嗎?

<a href="#" class="classnameofyourlink" data-id="3">link</a> 

[].forEach.call(document.querySelectorAll('.classnameofyourlink'), function (el) { 
    el.addEventListener('click', function() { 
     // put your stuff here 
     // retrieve the {{ID}} like this: this.getAttribute('data-id')); 
    }, false); 
});