我想要做的是定义一次变量,然后在可以使用时使用相同的文本。有时候我使用alert
,confirm
return
等等,所以我创建了一个使用全部3的快速示例,以防过程因使用情况而略有不同
示例:
$(document).mousemove(function(event){
var result = confirm("text that i want to create a var for here");
});
$(document).ready(function(){
alert("text that i want to create a var for here");
});
$(window).on('beforeunload', function(){
return "text that i want to create a var for here";
});
我试图做的是:
var test = "text that i want to create a var for here";
然后我将test
上面的代码替换为"text that i want to create a var for here"
哪里有var test = "testing text here"
哪个不起作用,所以我定义一次的正确方法是什么,然后使用变量代替文本?
更新
我使用了基本变量,例如
var test = "text row 1 \n\n text row 2 \n\n number "+number+" text row3"
但下面是我遇到问题的一个例子:
### Python 3.X ###
import sys
import time
import openpyxl
from openpyxl.styles import Alignment, Font, Style
from openpyxl.cell import get_column_letter
from pathlib import Path
###Double Click a Batch file, CMD opens, Client drags and drops excel File
###to be Formatted
try:
path = sys.argv[1]
except IndexError:
path = Path(input('Input file to read: ').strip("'").strip('"'))
output_string = str(Path(path.parent, path.stem + '.NewFormatted.xlsx'))
wb = openpyxl.load_workbook(str(path))
sheet1 = wb.worksheet[0]
###Do the Python Dance on Data###
###Style, Font, Alignment applied to sheets###
###Currently Saves output as a NEW excel File in the Directory the original
###file was drag and dropped from
wb.save(output_string)
###Need the output to be appended to an existing Excel file already present
###in a target directory
###Note Formatted Workbook (output) has multiple sheets###
我在猜测" +数字+"导致问题给我,所以我该如何解决?
答案 0 :(得分:1)
我想知道这个问题是不是很诱人。您需要在需要变量的所有回调函数之前定义变量:
var myText = "text that i want to create a var for here"
$(document).mousemove(function(event){
var result = confirm(myText);
});
$(document).ready(function(){
alert(myText);
});
最后一个示例不合适:您无法获取附加到DOM事件的回调函数的返回值。