使用Javascript在文本区域中添加新行
Adding a newline in a textarea using Javascript
我有一个iframe弹出窗口,允许用户添加信息。添加后,我希望它被添加到一些隐藏的输入中(在本例中为文本区域)。
我需要使用以下C#代码添加一个连接的地址字符串:
public string AddressInputFormatted { get { return string.Format("{0}{4}{1}, {2} {3}", Address, City, State, Zip, Environment.NewLine); } }
甚至(两者都试过):
public string AddressInputFormatted { get { return string.Format("{0}'n{1}, {2} {3}", Address, City, State, Zip); } }
我得到了它,并在回发时创建了一个启动脚本:
Dim strScript As String = "window.parent.$('.contact.name').html('{0}');" & _
"window.parent.$('.contact.title').html('{1}');" & _
"window.parent.$('.contact.email').html('<a href=mailto:{2}>{2}</a>');" & _
"window.parent.$('.contact.address').html('{3}');" & _
"window.parent.$('textarea.contact.address').val('{9}');" & _
"window.parent.$('.contact.work-phone').html('Phone: {4}');" & _
"window.parent.$('.contact.mobile-phone').html('Mobile: {5}');" & _
"window.parent.$('.contact.fax').html('Fax: {6}');" & _
"window.parent.$('#hiddenCustomerID').val({7});" & _
"window.parent.$('.getCustomerName').val('{8}'); window.parent.$('.customer.name').html('{8}'); parent.$.fn.colorbox.close();" & _
"window.parent.$('.change-contact').show(); window.parent.$('.add-contact, .autoCompleteCustomerContacts').hide();" & _
"window.parent.$('.change-customer').show(); window.parent.$('.add-customer, .autoCompleteCustomersWithID').hide();"
strScript = String.Format(strScript, contact.FullName, contact.Title, contact.Email, contact.AddressInputFormatted, contact.WorkPhone, contact.MobilePhone, contact.Fax, contact.CustomerID, customer.Name, contact.Address)
ScriptManager.RegisterStartupScript(Page, Me.GetType(), "updateParent", " $(document).ready(function () {" & strScript & " });", True)
无论哪种方式,我在页面上看到了实际的javascript,并返回了一行,然后我得到了一个javascript错误:
SyntaxError: Unexpected token ILLEGAL
我做错了什么?如何使用javascript在隐藏文本区域中存储新行?
您需要转义符,以便HTML输出包含'n
:
public string AddressInputFormatted
{
get
{
return string.Format("{0}''n{1}, {2} {3}", Address, City, State, Zip);
}
}
相关文章:
- 如何在脚本上添加新行
- 在不刷新整个网格的情况下,向Asp.net网格视图添加新行
- dhtmlx添加新行并启动单元格编辑器
- 如何在Google Geochart图表的工具提示文本中添加新行
- 如何在javascript中每次添加新行时都增加ordre值
- 两个表添加新行按钮-冲突
- 在Spring.message属性中添加新行时出错
- 使用Javascript在文本区域中添加新行
- 在java脚本的第一行之前添加新行
- sails.js更新或添加新行
- 使用ajax向表中添加新行
- 使用一些默认值在剑道网格中添加新行
- 添加新行后无法“刷新”灯丝组表锯响应表
- JQuery 数据表添加新行,如果该行已经存在,请将其删除并为该 ID 插入新行
- 续集 - 向表添加新行并关联表
- 如何在 jQuery 函数 text() 中添加新行
- 在表格顶部添加新行
- 添加新行动态引导日期时间选择器不起作用
- 如何在不影响 Jquery 数据表中其他行的情况下删除选定的现有数据并添加新行
- 分机.js确认方法添加新行字符