我將公司名稱傳遞給onclick事件。一些公司名稱中有撇號。我將''替換(「'」,「'」)'到company_name字段。這允許觸發onclick事件,但確認消息顯示爲「Jane &#s焊接公司」。在onclick事件中傳遞參數時忽略撇號
<a href="#" onclick="return Actionclick('<%= Url.Action("Activate", new {id = item.company_id}) %>', '<%= Html.Encode(item.company1.company_name.Replace("'", "'")) %>');" class="fg-button fg-button-icon-solo ui-state-default ui-corner-all"><span class="ui-icon ui-icon-refresh"></span></a>
<script type="text/javascript">
function Actionclick(url, companyName)
{
if (confirm('This action will activate this company\'s primary company ('+companyName+') and all of its other subsidiaries. Continue?'))
{
location.href = url;
};
};
EDIT 該確認消息表示&#39;在消息而不是'。當我在這裏輸入時,它取代了這個名字。與'。增加空間,這樣就不會發生。我想知道將它傳遞給我的onclick事件的最佳方式,並且在不做多次替換(如果有更好的方法)的情況下正確顯示它在消息中。
也許我很愚蠢,但是這裏的具體問題是什麼?你不想要'在確認信息中或你想要'嗎? – griegs 2010-05-17 00:19:55
哎呀。請參閱編輯。 – RememberME 2010-05-17 00:25:37