我需要使用javascript制作文本框粗体/斜体/下划线的选定文本.为此,我使用以下代码.
<img src="~/images/Bold" alt="Bold" onclick="changeFont('TextBox1','b');" />
<img src="~/images/Italic" alt="Italic" onclick="changeFont('TextBox1','i');" />
<img src="~/images/Underline" alt="Underline" onclick="changeFont('TextBox1','u');" />
Run Code Online (Sandbox Code Playgroud)
<script type="text/javascript" language="javascript">
function changeFont(txt, change) {
if (change == 'b') {
if (document.getElementById(txt).style.fontWeight == 'bold')
document.getElementById(txt).style.fontWeight = 'normal';
else
document.getElementById(txt).style.fontWeight = 'bold';
}
else if (change == 'i') {
if (document.getElementById(txt).style.fontStyle == 'italic')
document.getElementById(txt).style.fontStyle = 'normal';
else
document.getElementById(txt).style.fontStyle = 'italic';
}
else {
if (document.getElementById(txt).style.textDecoration == 'underline')
document.getElementById(txt).style.textDecoration = 'none';
else
document.getElementById(txt).style.textDecoration = 'underline';
}
}
</script>
Run Code Online (Sandbox Code Playgroud)
但是这里的问题是,当我点击粗体图像时,它会将整个文本变为粗体而不是所选文本.它也不适用于其他两个图像.
保存文本框的文本时,即使尝试使用,我也无法获取包含html标签的文本
document.getElementById('TextBox1').innerHTML;
Run Code Online (Sandbox Code Playgroud)
我只能获得文本框的值.
有没有办法使用javascript或C#保存和检索相同的内容
在此先感谢SC
我们在桌面应用程序(C#)中使用save/opn文件对话框.当我们第一次打开对话框时,句柄增加100.关闭对话框后,句柄不会减少.从下一次起,手柄增加10左右,减少2到4.
我们尝试通过调用dispose并使其为null来减少句柄.并尝试使用块.但他们都没有解决这个问题.
你能告诉我任何解决方法吗?或者我们可以使用任何自定义控件
请就此提出建议
提前致谢
代码:代码是
SaveFileDialog objSaveDialog = new SaveFileDialog();
try
{
objSaveDialog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
objSaveDialog.Title = "Save to Text File";
//objSaveDialog.ShowDialog();
DialogResult dlgResult = objSaveDialog.ShowDialog();
objSaveDialog.Dispose();
if (dlgResult == DialogResult.OK)
{
string strSaveFilePath = objSaveDialog.FileName;
if (!string.IsNullOrEmpty(strSaveFilePath))
{
TextWriter myTxtWriter = new StreamWriter(strSaveFilePath, false);
for (int index = 0; index < 10000; index++)
{
myTxtWriter.WriteLine("sample text.....................................");
}
myTxtWriter.Flush();
myTxtWriter.Close();
myTxtWriter.Dispose();
}
}
}
finally
{
if (objSaveDialog != null)
{
objSaveDialog = null;
//((IDisposable)objSaveDialog).Dispose(); …Run Code Online (Sandbox Code Playgroud)